How am I able to call the built-in WordPress functions (specifically wp_get_user()) in a different file (say, x.php)?
Here's my situation. If I call wp_get_current_user() on the index.php file within my theme directory, it works just perfectly.
However, if I have x.php and called that, I got an error. I googled around, and am now including wp-load.php (at it's correct path). Now it's just giving me an associated array with no values.
The associated array is:
WP_User Object ( [data] => [ID] => 0 [id] => 0 [caps] => Array ( ) [cap_key] => [roles] => Array ( ) [allcaps] => Array ( ) [first_name] => [last_name] => [filter] => )
I tried including index.php in this file, and it still spits out that stuf above, instead of the correct information (which is shown by a print_r on index.php).
Thank you!
try also including the header <?php require('{correct_path}/wp-blog-header.php'); and if that doesn't work also try re-declaring the variables your using to global $var in your wordpress setting php.
See http://codex.wordpress.org/Integrating_WordPress_with_Your_Website
First, use either
<?php define('WP_USE_THEMES', false); require('./wp-blog-header.php'); ?>
or
<?php require('/the/path/to/your/wp-blog-header.php');?>
and then call your WP functions.
Related
I'm trying to follow this solution to export data to excel but when I click the download link it just says "Server Error. May be down for maintenance....etc"
The only thing I had to change from the tutorial is the name of the Csv helper. The tutorial specifies "Csv.php" but I had to name it "CsvHelper.php". When I print the variable that goes to this view, it displays the array. However, when I remove this and just have the code listed exactly as it appears in that linked post from above I get a server error
HTTP Error 500 (Internal Server Error): An unexpected condition was encountered while the server was attempting to fulfill the request.
These are the files that I had to add to my server as directed by the "tutorial"
//Helper
/App/View/Helper/CsvHelper.php
//Vendor
/App/Vendor/excel/PHPExcel.PHP
/App/Vendor/excel/PHPExcel/ //contains the rest of PHPExcel
//view
/App/View/Orders/download.ctp //Tutorial specifies /App/View/Homes/download.ctp so I made sure to change the link accordingly in the view which actually "links" to this
As I mentioned previously when I print the array on download.ctp see this
Array ( [0] => Array ( [Order] => Array ( [id] => 1 [userid] => 2 [order_status] => completed [email] => test#gmail.com [total] => 8.00 ) )
My array's structure matches that of the tutorial which is
$orders[0]['Order'];
Is there something I have to configure with CakePHP for downloading files? I have no idea where to go from here.
Outputting different types of content in cake 2.x is now easy and a "piece of cake" :)
View classes can easily be switched to whatever output you need (json, xml, csv, ..).
In your case I would use https://github.com/josegonzalez/CsvView .
$this->viewClass = 'CsvView.Csv';
and export the data as documented in the plugin readme.
I have installed two different PHP scripts on my server. One on root and another on different sub-directory. However, I want the root phpscript's users session to be continued on another sub-directory script. I need this session to enable chat even on another directory script.
The sub directory is os-class.
I made a different PHP file on sub-directory to track session variables.
Array ( [user_email] => xxxx#example.com
[users_id] => 275
[first_name] => Sammy
[last_name] => Durha
[username] => 275
[mobile] => XXXXXXXXX
[chat_sms_sent] => message sent to off line friends. )
However on one of the script page the half session gets lost.
Array ( [messages] => Array ( )
[keepForm] => Array ( )
[form] => Array ( )
[chat_sms_sent] => message sent to off line friends. )
Can anyone please sort out the problem.
Thanks
Sessions are not tied to a directory. If you call session_start() at the top of both scripts, the $_SESSION variable should have the same content in both.
Session is independent of directories and files. It can be used universally. But remember that sessions are less secure.
You may follow a simple tutorial here.
All time I use:
print'<pre>';
print_r($var);
print'</pre>';
to debug php.
I want to collapse this tree
[params] => JRegistry Object
(
[data:protected] => stdClass Object
(
[show_title] =>
[link_titles] =>
[show_intro] =>
with jquery
I use Kint which is Excellent. To use it, just type :
// shows name of variable, collapsible value and place you called it from
d(varname);
/* pretty stack trace that lets me expand the source, and see
the parameters passed to the function; same is achieved via `d(1);` */
Kint::trace()
Screenshot:
(source: github.io)
Give Krumo a try - http://krumo.sourceforge.net/
Well, it is a litte bit strange, since I remember that if I wan't to go to the directory back, then I need to do the following: include("../something-in-back-folder.php"); but it throws up an error with message that the file was not found. So I've prepared some code to check this out:
echo "<pre>".print_r(scandir("../"), 1)."</pre>";
I've executed it in file with location:
public_html => app => actions => post.php
but the above code said, that back from my direction there are the following folders:
Array
(
[0] => .
[1] => ..
[2] => private_html
[3] => public_html
)
It should return 'actions' folder instead. Right?
Isn't this strange? Or I've missed something? If so, then how can I include/open something that is one(or even two) folders back from my current directorty?
You are correct that the .. notation indicates a reference to the parent folder. Your analysis reveals that your PHP current working directory is at the public_html level; this isn't unusual. Make your reference relative to PHP's current working directory. Assuming you want to get at the 'actions' folder from post.php, say:
include('app/actions/something-in-back-folder.php');
I have a problem regarding the spoon-library (www.spoon-library.com). I have a folder with subfolders, each subfolder is a 'reference' from my dad his company. (although its translated to my native language). Each of the 'reference' subfolder contains images.
I am reading the names of al subfolders and the images that are in that specific folder and save it to an array. With the use of spoon-library i am nesting these in template variable in my tpl files. So basically I print the <h2></h2> with the project's title (the subfolder name), and all his images (so that they can be viewed through lightbox).
On my localhost and my website (provider A) it works, but when i upload it to my dad his hosting (provider B) it doens't work.
ex.
http://davyloose.be/electroloose/projecten.php -> it works.
http://electro-loose.be/projecten.php -> it doens't work.
The code is identical.
Example of the array with the data that i get through the folders (note, i get the same data on both webspace):
Array (
[0] => Array (
[title] => Apotheek Beerlandt
[images] => Array (
[0] => Array ( [url] => beerlandt 2.JPG )
[1] => Array ( [url] => beerlandt 3.JPG )
[2] => Array ( [url] => beerlandt 1.JPG )
)
)
)
This is entered in the following 'html' code (template file):
{iteration:referenties}
<h2>{$referenties.title}</h2>
<div id="imageslide">
{iteration:referenties.images}
<img src="/images/referenties/{$referenties.title}/thumbs/{$referenties.images.url}" />
{/iteration:referenties.images}
</div>
{/iteration:referenties}
Note: references in my native language is 'referenties'.
It seems that on my dad his webhosting a '.' changed to '->', although i'm not really sure (as in 'I can't believe that).
The php version on my localhost and my webhosting are PHP5.3.5, the version on my dad his hosting is 5.1.2.
I hope you guys can help me out on this one :).
PS: I know i can fix this with the use of an sql database. And i'm going to do that in the near future, but for now i just want to know why this error is occurring.
Thanks in advance!
Edit: I just enabled the display_errors in my php.ini and now i see the following error 'Notice: Undefined variable: count in /var/www/html/test/spoon/template/compiler.php on line 913' (and also on some other lines). Still, it's a mystery why it works on my localhost and not on my dad his host.
I'm the author of Spoon Library. I believe the issue lies with the differences in the PHP versions. The $count parameter that the notices are talking about were added in PHP5.1, but for some reason they don't seem to work exactly as expected in the PHP version on your dad's host.
I'd recommend to try and get the hosting to use at least PHP5.2, because there are another few issues that might occur within other spoon packages because of this.
If you need any more help you can always find me on twitter(#spoonlibrary) or e-mail me (davy#spoon-library.com)