Tag Info

New answers tagged

0

Personally I would use wp_get_current_user(), no globals: function plugin_admin_init() { $user = wp_get_current_user(); }


1

By default, the add_action function is only going to pass 1 parameter, but you can define how many do you have / need $accepted_args (int) (optional) The number of arguments the hooked function accepts. In WordPress 1.5.1+, hooked functions can take extra arguments that are set when the matching do_action() or apply_filters() call is run. So ...


1

Even if is not very flexible filter you can use the gettex hook. Only be aware that this filter runs for every string being translated, so can affect performarce if over-used. To narrow the performance impact you can add it only of admin footer, and remove it just after had use it: add_action('admin_footer', function() { add_filter( 'gettext', ...


1

The hooks you are looking for can be found in the WordPress Codex WP_Query - Filters: Filters posts_distinct - Alters SQL 'DISTINCTROW' clause to the query that returns the post array. posts_groupby - Alters SQL 'GROUP BY' clause of the query that returns the post array. posts_join - Alters SQL 'JOIN' clause of the query that returns the post ...


0

Your custom script uses $'s and thus does not account for "noConflict" mode. Use a proper no-conflict wrapper, or simply replace "$" with "jQuery" everywhere. More info: http://codex.wordpress.org/Function_Reference/wp_enqueue_script#jQuery_noConflict_Wrappers The $ shortcut is not valid in all contexts. You need to stop using it when possible, or define ...


2

Scripts and stylesheets should always be loaded in the head or in the footer via the wp_enqueue_scripts action hook. wp_enqueue_scripts is the proper hook to use when enqueuing items that are meant to appear on the front end The init hook executes before wp_head which is to early for script to load in the header. The wp_enqueue_scripts action hook is ...


2

You should first load your scripts with a hook on wp_enqueue_scripts like this for example : add_action( 'wp_enqueue_scripts', 'load_my_scripts' ); function load_my_scripts() { wp_enqueue_script( 'jquery' ); } What I like to do is, register my script with a hook on init and then enqueue them with a hook on wp_enqueue_scripts: // Register Scripts ...


1

Couple of things: 1: When you include the script after jquery, localise it using the wp_localize_script function: $nonce = wp_create_nonce("vote_nonce"); $yourscript_info = array( 'ajaxurl' => admin_url( 'admin-ajax.php'), 'nonce' => $nonce ); wp_localize_script( 'yourscript', 'yourscript', $yourscript_info ); $.ajax({ type: "POST", ...


0

Found the problem! It was the is_single() line. It's not working because its outside the loop.


0

This is the solution from Peter Baylies (Plugin Author) add_filter( 'option_aioseop_options', 'itdge_sitemap_addl_pages' ); function itdge_sitemap_addl_pages( $option ) { if ( !empty( $option ) && !empty( $option['modules'] ) && !empty( $option['modules']['aiosp_sitemap_options']) ) { $my_sitemap_entries ...


0

This is not a solution to my question but it helps me to solve my problem in Wordpress, and I want to share it. I create a separate sitemap using XMLWriter. Here is the code. Wordpress hook: add_action('parse_request', 'my_custom_url_handler'); function my_custom_url_handler() { $c = new EventsSitemapBuilder(); if( $_SERVER["REQUEST_URI"] == ...


0

You need to set the number of arguments your filter accepts: add_filter( 'the_title', 'alternatives_title', 10 /* Priority */, 2 /* Arguments */ ); And you only need to use the_title (there is no get_the_title filter).


0

You have to called this function in your header.php (your wp theme) : <?php wp_head(); ?> And this one into your Footer.php : <?php wp_footer(); ?> Because you are adding action to your Wordpress, so you have to call that function in your theme.


2

You can check the $current_screen on the current_screen action, and redirect after checking some GET conditions: function wpd_current_screen( $current_screen ) { if ( 'toplevel_page_your_menu_item_id' == $current_screen->base ) { // check some condition and wp_redirect( admin_url() ); exit; } } add_action( ...


7

You can try this: is_admin() && add_filter( 'gettext', function( $translated_text, $untranslated_text, $domain ) { $old = "Plugin <strong>activated</strong>."; $new = "Captain: The Core is stable and the Plugin is <strong>activated</strong> at full Warp speed"; if ( $untranslated_text === ...


2

Some things non-WordPress specific regarding cookies: set cookie fails if some output has been done in the page you can't access to coockie value in the same request you set it (as @Milo pointed out in a comment to OP) Another general rule is better to use filter_input or filter_intput_array instead of direct accessing to super globals like $_GET or ...


2

I would use the registration_redirect filter. This allows you to set where the user is sent to, but leaves WordPress to perform the redirect (after everything has successfully processed). function wpse_139267_registration_redirect( $url ) { return site_url( 'thank-you' ); } add_filter( 'registration_redirect', 'wpse_139267_registration_redirect' );


0

I don't really like plugins that you still need to modify your theme's template file manually. What is the use then of a plugin. To come back to you question though, your do_action() call will need to go in the template where you need to display the output of the plugin. Say it is a plugin that add social share buttons to the content, you will need to add ...


1

You are already pretty close. Extending your example: In your plugin put this: $default_settings = array( 'key_one' => 0, 'key_two' => 1 ); $settings = apply_filters( 'example_filter', $default_settings); Then a theme can change it like this: add_filter('example_filter','my_function'); function my_function($settings){ $settings['key_one'] ...


0

Place Order Button can't go out of the <form></form> element. What you can do is you can duplicate the button within the element but at the top. like this: For this: Withing you child theme make a folder woocommerce and inside that checkout. Now go to wp-content\plugins\woocommerce\templates\checkout and copy form-checkout.php file and ...



Top 50 recent answers are included