Use plugin function outside WordPress file

If you are intent on calling into WordPress functionality from outside of the usual WP workflow, you can put the following two lines in your code: define(“WP_USE_THEMES”, false); require_once(“../../../wp-blog-header.php”); Of course, the above assumes I’m calling this from within a root theme or plugin folder (the ../ indicates reverse folder traversal). It looks as though … Read more

How to localize value of posts

Try: function register_and_enqueue_script() { if(‘myPostType’ == get_post_type() && have_posts()) { wp_register_script( ‘js_script’, plugin_dir_url(__FILE__).’js/script.js’, array(), ‘1.8.5’ ); wp_enqueue_script(‘js_script’); $myCustomValue = array(); while(have_posts()) { the_post(); $mypostid = get_the_ID(); $myCustomValue[”.$mypostid] = nl2br(get_post_meta($mypostid, ‘custom_value’, true)); } // end while rewind_posts(); wp_localize_script(‘js_script’, ‘myCustomValue’, $myCustomValue); } // end if }

delete_user_meta Delete one value out of array

Thanks yo Howdy_McGee, Here is working code. // Remove favorite authors from current users DB function fav_author_remove_user(){ check_ajax_referer( ‘fav_authors_obj_ajax’, ‘security’ ); $remove_this_author = $_POST[‘clicked_author_id’]; if ( current_user_can( ‘edit_posts’ ) ){ $user_id = fav_authors_get_user_id(); $author_list = get_user_meta( $user_id, FAV_AUTHORS_META_KEY, true ); //print_r($author_list); $author_saved = array_search($remove_this_author, $author_list); if( FALSE !== $author_saved ){ // Remove $author_saved unset($author_list[$author_saved]); $author_arr … Read more

WordPress Plugin development Call to undefined function jQuery()

You need specify jquery as a dependency of your custom script, setting the 3rd parameter of wp_enqueue_script() to array(‘jquery’), like this: wp_enqueue_script( ‘yourCustomScript’, plugins_url(‘js/yourCustomScript.js’, __FILE__), array(‘jquery’), ‘1.0.0’, false ); Change the path to point to your custom-script file As to your last question, the answer is affirmative. You need a .js file. Basically WP needs … Read more

What is $tab in `install_plugins_{$tab}` hook?

If you go to the plugin-install.php inside the WordPress dashboard, there may be many tabs: wp-admin/plugin-install.php?tab=featured wp-admin/plugin-install.php?tab=popular wp-admin/plugin-install.php?tab=recommended … Here is the function you referenced: File: wp-admin/plugin-install.php 145: /** 146: * Fires after the plugins list table in each tab of the Install Plugins screen. 147: * 148: * The dynamic portion of the action … Read more

How to edit plugin’s html? [closed]

You should have the option to edit any plugin’s code from the plugins screen. Under the name of each plugin you should see an Edit link which gives you access to the plugin code. Any changes that you make to the plugin will be completely wiped out when the plugin updates unless you ensure that … Read more