I'm trying to enable file uploads via a simple HTML form on a Wordpress page by using an AJAX POST to upload-manager.php.
The problem is, when the post is triggered, the returned data is not what is being echoed in upload-manager.php. Instead, the data being returned is a home page in an HTML string when logged to the console.
Maybe there is a confirmation URL set somewhere in WordPress that's causing this?
I've tried using wp_dequeue_script() in my child theme in hopes that maybe it would prevent POST event listeners from being set via some other script in the theme.
//DEQUEUE Specific scripts
function project_dequeue_unnecessary_scripts() {
wp_dequeue_script('nectar-upload');
wp_deregister_style( 'nectar-upload' );
wp_dequeue_script('redux-opts-field-upload-js');
wp_deregister_style( 'redux-opts-field-upload-js' );
}
add_action( 'wp_print_scripts', 'project_dequeue_unnecessary_scripts' );
//DEQUEUE all scripts
function pm_remove_all_scripts() {
global $wp_scripts;
$wp_scripts->queue = array();
}
add_action('wp_print_scripts', 'pm_remove_all_scripts', 100);
Neither works.
It's also worth noting the in the dev tools network panel > XHR, I get the following:
Then after ~2 seconds it changes to:
Does this mean my jQuery AJAX POST is being redirected or something?
Please help!
Within a plugin I am adding a filter to catch and append to / update the content of a certain page. If I just explicitly write the markup out in the same function it works, but if I try to load the exact same content from a file it seems to break the page (jQuery issues I believe).
works
function custom_content($content) {
$content = '<div>Hello World</div>';
return $content;
}
doesn't without causing client side errors?
function custom_content($content) {
$content = file_get_contents(plugins_url('/html/file.html', __FILE__));
return $content;
}
contents of the html file
'<div>Hello World</div>;'
Just curious to know why this isn't the same. I am not attempting to load my own version of jQuery or anything. Both of these get loaded properly with add_filter, but if I try to use the second it doesn't work but the first does. My thought would be that the get_file_contents should only load those contents and resolve the reference before page is born?
EDIT: I see a bunch of jQuery ref errors on the page when I try to load contents from the file.
$()... is not defined
Always appreciate the help!
im still new to wordpress and not that good in coding much in php but i do know the basics. I have here my main code file for my plugin called hello-world.php and another php file called display-data.php. i kinda confused on how you display data by using a function to call it on another page which in mine called display-data.php here is my code for hello-world.php
function wpdisplay(){
global $wpdb;
global $result;
$result = $wpdb->get_results("
SELECT * FROM wp_options WHERE option_id = '262'
", ARRAY_A);
print_r($result);
}
register_activation_hook('activate_hello-world/display-data.php' ,'wpdisplay');
i have a button form in my main file that directs to display-data.php where it should display the data. i tried calling it by wpdisplay();
however it gives me an error like this.
Call to undefined function wpdisplay() in /Applications/MAMP/htdocs/wordpress/wp-content/plugins/hello-world/display-data.php
hope you could help me and explain if there is something that i am missing. thanks
Like error message says, you are calling a function that is not defined. To use a function that you have defined on a different file, you have to include that file.
I am getting a strange 500 Internal Server Error with a new script I am trying to implement in the actual site. Here's a screen:
![500 Internal][1]
I can route to this files manually without problems and they are working too. But not in the script itself. The Paths are also correct.
Heres the link to the Site:
[>>> Link <<<][2] (just enter R10369 in the input field or a random number)
Everything else is working correctly except these 3 files:
reseller.php,
checkresellerid.php,
resellermail.php
I googled a bit and everywhere is the .htaccess mentioned. but I never modified it or overwrited it. What could be the Problem? Thanks for any Help and sorry for my bad Englisch.
(Let me know if you want to see the php files)
EDIT: I managed to include my new php files into wordpress but i still got the 500 Error
I checked out the website.
I think Wordpress doesn't let you call .php inside of it's system.
I mean you cannot call PHP files for ajax.
You need to use wordpress ajax. Here is a snippet how to use ajax:
Function.php in your theme file.
function myajax()
{
//do stuff
die();
}
add_action( 'wp_ajax_nopriv_product_s', 'myajax' );
add_action( 'wp_ajax_product_s', 'myajax' );
And in your javascript file using jQuery:
The url may change, maybe it's enough to have wp-admin/admin.ajax.php or something like this, i don't really remember right now.
$.post('/wp-admin/admin-ajax.php',{action:'myajax',yourdata:"mydata"}).done(function(data)
{
//do stuffs
});
Update:
So basically if you want to have ajax request inside wordpresss, you need to define these things and use it like this. the "action" parameter is the function name which you want to call. And you need to put the PHP code into your current theme's function.php.
I am creating new shortcodes for Wordpress on my local version of a Wordpress website.
In functions.php, I am adding for example:
function shortTest() {
return 'Test for shortcodes ';
}
add_shortcode('shortTestHTML', 'shortTest');
Adding the function only is OK, but when I add the add_shortcode() portion, I get a major issue.
It breaks something somehow and I get 500 errors, meaning I can't even load my website locally anymore.
Any thoughts???
Thanks so much!
EDIT:
From PHP Error Log:
[21-Jun-2011 19:02:37] PHP Fatal error: Call to undefined function add_shortcode() in /Users/jonas/Sites/jll/wp-includes/functions.php on line 4505
1) Make sure that you have included shortcodes.php file somewhere (for example, in wp-load.php or whatever other more appropriate place may be).
require_once( ABSPATH . '/wp-includes/shortcodes.php' );
2) Make sure that this file does exist on your installation (which I think you have otherwise we would see a different error).
3) Where do you call this function from (I see it is called from functions.php, but which place)? Possible problem here -- functions.php is loaded prior to shortcodes.php, and if you do use that add_shortcode function before shortcodes.php is loaded you most likely will see this error. Double check your code in that place -- maybe move the call to add_shortcode to another place.
mentioned functions.php is not in wp-include/ directory.
it is in: wp-content/themes/<your-theme-name>/functions.php
adding this in functions.php you say? Well I don't know about that, the way I did it was create a folder inside the wp-content/plugins folder, e.g. shortcodetest.
Inside this folder create a shortcodetest.php file.
in that file you basically write your code:
<?php
/*
Plugin Name: ShortCodeTest
Plugin URI: http://www.example.net
Description: Print a test message
Version: 0.1
Author: anonymous
Author URI: http://www.example.net
*/
add_shortcode('shortcodetest', 'shortcodetest_function');
function shortcodetest_function() {
return "test of shortcode";
}
?>
Then you login as admin, you will see a plugin ShortCodeTest, activate it. Then you can use the shortcode in your posts.
Note that the comments are important... they show up in the plugin description.
I got a way to execute them but it's a little triky :)
You need to change a little bit your template by putting your shortcode (for example: [inline ....]) between <shortcode></shortcode> then
Here is the function to place at the end of your function.php.
function parse_execute_and_echo_shortcode($_path) {
$str = file_get_contents($_path);
while (strrpos($str, "<shortcode>")) {
$beginShortcode = strrpos($str, "<shortcode>");
$endShortcode = strrpos($str, "</shortcode>");
$shortcode = substr($str, $beginShortcode + 11, $endShortcode - ($beginShortcode+11));
$shortcode = do_shortcode($shortcode);
$str = substr_replace($str, $shortcode, $beginShortcode, $endShortcode + 12);
}
echo $str;
}
Then you can call function parse_execute_and_echo_shortcode and giving it the path to your file containing the shortcodes.
Hope that can help someone
Check your error.log file (it should be in your apache log folder).
It probably has to do with add_shortcode not existing as a function.
Put your shortcode in the file /wp-includes/shortcodes.php this way you make sure it will be loaded when all the blows and whistles are up and running.