I wrote a PHP script to process files sent to it via POST.
On the frontend js script, I create a Formdata object, and append images to it...like:
formdata.append('image0', image0);
formdata.append('image1', image1);
etc
This is my PHP code, the code is in the wordpress root directory
<?php
header("Access-Control-Allow-Origin: *");
require_once('wp-admin/includes/image.php' );
require_once('wp-admin/includes/file.php' );
require_once('wp-admin/includes/media.php' );
$id_array = array();
$c = 0;
foreach ($_FILES as $file) {
$id_array[] = media_handle_upload('image' . $c, 0);
$c++;
}
echo implode(',', $id_array);
However when I run this code, I get the following error:
Fatal error: Call to undefined function __() in /home/website/public_html/wp-admin/includes/file.php on line 16
Am i missing to include additional files in the script? I used the documentation on wordpress and it said:
These files need to be included as dependencies when on the front end.
require_once( ABSPATH . 'wp-admin/includes/image.php' );
require_once( ABSPATH . 'wp-admin/includes/file.php' );
require_once( ABSPATH . 'wp-admin/includes/media.php' );
I would appreciate any help!
In order to use the native Wordpress functions, such as __() wp-config.php needs to be included additionally.
Adding wp-config.php solved the issue
I'm also facing same issue.
Adding this in functions.php will fix the error.
Some time it will show as "http error"
add_filter( 'wp_image_editors', 'raj_change_graphic_library' );
function raj_change_graphic_library($array) {
return array( 'WP_Image_Editor_GD', 'WP_Image_Editor_Imagick' );
}
Related
I am using an index.php file to include the header, navigation and footer on all pages on my site, however I have an issue with my php which is showing all pages within the pages folder at once, rather than just showing the page I'm currently on.
Here is the PHP I am using, any advice would be appreciated!
<?php
$files = scandir( __DIR__ . '/pages' );
unset( $files[0] );
unset( $files[1] );
foreach($files as $file){
include __DIR__ . '/pages/' . $file;
}
?>
Then just remove the whole script and use <?php include('yourDesiredfile.php'); ?> for the files you would like to include.
I am trying to delete rows from db and getting this error. I googled and tried all the possible solution still no luck. I also mentioned "global $wpdb" but dont know why getting this error.
<?php
if($_POST['array'])
{
global $wpdb;
$productArray = $_POST["array"];
$count = count($productArray);
$table_name = "wp_cause_woocommerce_product";
for( $i=0; $i < $count; $i++ ){
$wpdb->delete( $table_name, array( 'product_ID' => $productArray[$i] ), array( '%d' ) );
}
}
I think the issue is that you are not getting the WordPress functions.
Add this in to the top of your code.
define('WP_USE_THEMES', false);
require_once( $_SERVER['DOCUMENT_ROOT'] . '/fundraise/wp-load.php' );
If you change your project path make sure you update the path to wp-load.php.
If you will change your project path in future, you can try this
define('WP_USE_THEMES', false);
require_once( dirname(dirname(dirname(dirname(dirname(__FILE__))))) . '/wp-load.php');
Hope this helps.
I just add the below lines on top of the page and its working. I had to relate the file with wp functionality thats it :
define('WP_USE_THEMES', false);
require_once( $_SERVER['DOCUMENT_ROOT'] . '/fundraise/wp-load.php' );
Months ago, I have placed a 301 redirect rule in my .htaccess file to redirect all the www request to a non-www request.
The problem is two days ago, when I tried to access my example.net site using www.example.net I get the following warnings in the page and website is not loaded.
http://i.stack.imgur.com/nXBMF.png
Here are the corresponding lines:
1. Plugin.php Line 647 = if ( strpos( $file, $realdir ) === 0 ){
Full function:
/**
* Gets the basename of a plugin.
*
* This method extracts the name of a plugin from its filename.
*
* #since 1.5.0
*
* #param string $file The filename of plugin.
* #return string The name of a plugin.
*/
function plugin_basename( $file ) {
global $wp_plugin_paths;
foreach ( $wp_plugin_paths as $dir => $realdir ) {
if ( strpos( $file, $realdir ) === 0 ) { /** LINE 646 */
$file = $dir . substr( $file, strlen( $realdir ) );
}
}
$file = wp_normalize_path( $file );
$plugin_dir = wp_normalize_path( WP_PLUGIN_DIR );
$mu_plugin_dir = wp_normalize_path( WPMU_PLUGIN_DIR );
$file = preg_replace('#^' . preg_quote($plugin_dir, '#') . '/|^' . preg_quote($mu_plugin_dir, '#') . '/#','',$file); // get relative path from plugins dir
$file = trim($file, '/');
return $file;
}
2. Pluggable.php Line 1178 = header("Location: $location", true, $status);
Full file: http://pastebin.com/0zMJZxV0
I use WordPress only to write some articles. My PHP knowledge is very basic and limited only to locate errors.
Please help me figure out the problem with this. As I have read from the Codex FAQ, they say that empty strings may be a culprit for the pluggable.php error. But I have no idea how to locate it and I have attached the file for your reference.
Please provide your suggestions to avoid this error in the future. Thanks in advance.
3. EDIT - wp setting file: (the error line - include_once( $plugin ); )
// Load active plugins.
foreach ( wp_get_active_and_valid_plugins() as $plugin ) {
wp_register_plugin_realpath( $plugin );
include_once( $plugin );
}
unset( $plugin );
The issue with the header information has been discussed in here: Cannot modify header information error in Wordpress. Could you give this a try and see whether this solves this part of your problem?.
On the other issue:
try var_dump ($file) (for instance -- or echo $file ) to see what they actually contain.
Check your configuration path of plugins :
var_dump($wp_plugin_paths);
You've got an error because $realdir is empty.
In kohana 3.3 i need to include one of the controller file in the another controller
I used require_once( realpath(dirname(FILE) . '/Twitteroauth.php' ) );
Its showing the server error.
Thanks in advance.
You should do this:
require_once( realpath(dirname(__FILE__) . '/Twitteroauth.php' ) );
Function realpath returns false when file does not exist, so you should maybe check result before require:
$path = realpath(dirname(__FILE__) . '/Twitteroauth.php' );
if(!empty($path))
require_once($path);
else
die("$path not found!");
Been scratching my head for a while on this one. I'm just getting started with using PHP/Thrift to communicate with HBase (I can do it fine w/Python). For some reason the code below is generating class 'HbaseClient' not found on the $client = new line:
$GLOBALS['THRIFT_ROOT'] = 'thrift';
require_once( $GLOBALS['THRIFT_ROOT'] . '/Thrift.php' );
require_once( $GLOBALS['THRIFT_ROOT'] . '/transport/TSocket.php' );
require_once( $GLOBALS['THRIFT_ROOT'] . '/transport/TBufferedTransport.php' );
require_once( $GLOBALS['THRIFT_ROOT'] . '/protocol/TBinaryProtocol.php' );
require_once( $GLOBALS['THRIFT_ROOT'] . '/Hbase/Hbase.php' );
try
{
$socket = new TSocket('127.0.0.1', 9090);
$transport = new TBufferedTransport($socket, 1024, 1024);
$protocol = new TBinaryProtocolAccelerated($transport);
$client = new HbaseClient( $protocol );
$transport->open();
}
catch (Exception $e)
{
echo "Exception: %e\r\n";
}
I have literally no idea why. In the Hbase.php include file the client is defined as such:
class HbaseClient implements \Hbase\HbaseIf {
Am I missing something glaringly simple here? (Full HBase.php here: http://pastebin.com/6kd9r2Se )
Thanks in advance!
I believe this is a namespace issue. Try putting :
namespace Hbase;
in the file instantiating the object or use the fully qualified name:
$client = new Hbase\HbaseClient( $protocol );
Are you sure you have placed the HBase folder under THRIFT_ROOT directory or outside?