I have a file structure like
example.com/mywordpress/ --contains WordPress
example.com/custompreview.php --preview getter outside wordpress
I am using wp-load.php to load wordpres and using its contents. I am able to recive published posts with no problem, I even know how to make query for previews but when preview get parameters comes to the script outside the wordpress folder (custompreview.php) obviously the wp-load.php calls exit and shows only access error message.
Example is worth thousand words:
example.com/custompreview.php?preview=true&preview_id=64&preview_nonce=1f2477c5d2&post_format=standard
Shows only message "You do not have permission to preview drafts"
What is causing this? What is the wp-load.php checking for? How to fix this? :)
If you are getting this while logged in -
the session cookie may be limited to the /mywordpress folder.
Unless explicitly specified, the cookie will be valid in the subdirectory it was set in (and all children).
I'm not sure whether it is possible to change WP's session cookie behaviour, but it may help to put the PHP file inside /mywordpress.
Related
After setting up a template file article.html in craft/templates folder, and creating the section article with the uri article and setting the entry template as article in the admin on trying to see the live preview of the page when I go to it in the entries list I get a craft page with the error:
Page not found
I thought it might have something with cache maybe, so I cleared that, but I still got the same error. Why I am getting this error, and how can I fix that?
It might be a database not updating issue, have you tried making a backup of your current database and start with a fresh one?
If not, then check .htaccess and your routes.
First crate a 404.twig file.
Open general.php file "config/general.php" and change the devMode to false.
I'm new to web development but i know some php basic stuff. Using ftp, i create directories then create simple php scripts there, simple as echoing a string. Which can be accessed like,
www.sampledomain.com/folder1/subfolder2/hello.php
After some time, my friend introduced me to wordpress which is what they described as CMS. I tried to visit her site www.majaflores.com then i click on some stuff there and i noticed the url changed to http://majaflores.com/project/if-i-let-you-in-please-dont-break-anything/
At first, its pretty normal for me because its just a link where there is a folder named "project" and inside it another folder named "if-i-let-you-in-please-dont-break-anything". But when she showed me the ftp folders directory, i didnt see any folder named "project" under main folder of the domain. How did wordpress manage to do this? and how can i implement this manually?
Just wanted to say that like most server-side code environments, PHP also let you parse URLs "manually" and decide what to do accordingly, be it return a file or generate some content.
You can find more information about how PHP is parsing URLs in here:
http://php.net/manual/en/function.parse-url.php
and some discussion regarding it in here:
URL handling – PHP vs Apache Rewrite
This is they way WordPress stores data. U can further see the setting under Permalink.
Under Permalink, u can have options to render ulr as page id, category names and more. You can also use your own format over there.
Just a note, WordPress stored data in database not as a content on FTP directory.
I have two custom templates saved in my templates folder.
One's called xxxx.php and another is xxxx-test.php.
They are the exact same files except one points to a live API and the other a test API.
In my xxxx.php file I have something like this:
if(empty($current_user->user_email)){
header("Location:/wp-login.php");die;
}
I dont have this in the xxxx-test.php.
I want to be able to access xxxx.php only when logged in hence why im checking for the email. For the xxxx-test.php I'd like to give full access.
My problem is that everytime i try to go to the xxxx.php page i get redirected to xxxx-test.php
Anyone know how to stop wordpress from doing this?
I want to make page cache of static pages in my WordPress theme (and basically I know how to implement it)
The problem is that when making theme - the first time when I "get any control" about what is happening is inside functions.php file of theme, and this file is loaded about 1 sec after request starts (before it is loading all wordpress functions stuff, I quess some sql - but I dont need that all as I'm using page cache, just want to render saved html - btw. thats what is cache about for me).
So the question is - Am I able to - from level of theme - take control of WordPress initialization before theme functions.php? - the best would be as soon as possible after request start
Why? Getting html from cache takes 0,05s in my case, and time from request start to functions.php is 1s so in sume it gives 1,05s that I could reduce to like 0,1s if I'm able to 'capture' request earlier.
I dont want to modify non-theme files like WordPress core files as many people will use this theme, but if there is no other way than maybe but I dont feel it would be good practice?
i guess this might help: http://codex.wordpress.org/Plugin_API/Action_Reference/init
this hook gets executed when wordpress has loaded but before anything is saved
Create a drop-in plugin called advanced-cache.php, put it in wp-content (not wp-content/plugins), put define('WP_CACHE', true); in wp-config.php, and get to work.
Make sure not to cache:
admin pages
404 pages
POSTed pages
pages with query strings
pages that will be redirected
etc
I am currently trying to write a couple of pages into my website that are not part of the wordpress site but I would like to be able to use the wordpress users. I have this working using the following code
require_once("../../../wp-load.php");
$current_user = wp_get_current_user();
Now I am able to use the $current_user variable for everything I need. However because I am includeing the wp-load.php file there is a lot of overhead that I really don't need.
My question is how can I get the current wordpress user without including wp-load?
I don't mind having to include a few extra files myself but I really don't need or want the entire wp enviroment to be set-up each time this page is called just so I can get the user.
What are you doing in those pages? I'm asking because, if you want to send some POST via ajax, you should check this.
If you don't use ajax, but you just need some pages where you can acces Wordpress functions, well somehow you must include wp-load because this file is loading Wordpress.
I suggest creating a file called page-custom-name.php in your theme folder, and publish an empty page with the exact title "Custom-name". Now when you'll be visiting www.yoursite/custom-name you will see that page, and you can get the current user info, or access other Wordpress functions.
Later edit:
This idea a partial solution: How about using hooks?
In your functions.php put these lines:
add_action('wp_login', 'aboutuser');
function aboutuser($username, $user)
{
$userObject = $user;
//find a solution to send this data to your url of your application
}
Basically, when users are logging in Wordpress, the aboutuser() function is executed, and it's get 2 params(in Wordpress 3.3; in earlier versions it gets only the username).
Now, when users are logging in we have acces to the wp user object. Maybe there is a way pass this data(a POST request) to your application and store it in a session.
I don't sure if it's possible though.