Tag Info

Hot answers tagged

7

Look at the declaration for the function: function add_settings_field( $id, $title, $callback, $page, $section = 'default', $args = array() ) { } The last parameter takes your arguments and passes them to the callback function. Example from my plugin Public Contact Data foreach ( $this->fields as $type => $desc ) ...


5

I think I've worked this out. First of all, you need to define your taxonomy. I'm pulling this code directly from the codex; however, I've added one parameter update_count_callback. I've set this to the cleverly titled my_update_count_callback. This just specifies that when a post of type post (this will be whatever CPTs you associate the taxonomy with) is ...


4

A creative solution would be to modify the actual form_id in the database during gform_before_delete_form so none of the proceeding actions will modify the form. Then you can hook into gform_after_delete_form and modify the form_id back. gform_before_delete_form form_id = form_id + 1000000 gform_after_delete_form form_id = form_id - 1000000 ...


4

I've taken the previous post and done 2 things with it: uses native WordPress http call functions cache the fact that the CDN is up for 20 minutes (you can tweak this). You really don't want to get the CDN content on EVERY page load. No point in speeding up your site with CDNs when you do that. $get_the_url = ...


3

It's not possible to call a private method through an action or filter. When calling add_action or add_filter, WordPress adds the callback to a list of callbacks for that specific action or filter. Then, when do_action or apply_filters is called, WordPress uses call_user_func_array to call the linked functions and methods. As call_user_func_array is not ...


3

The wp_list_comments() function uses the HTML comment list class Walker_Comment by default: A single comment is then displayed with the Walker_Comment::comment() method (#source). If the comment format is HTML5 then the Walker_Comment::html5_comment() is used instead (#source). The pingbacks are rendered with the Walker_Comment::ping() method (#source). ...


3

There is a FileUploaded event being fired in wp-includes/js/plupload/wp-plupload.js. Alternatively (and propably the better way) you may want extend wp.Uploader with your own success callback . (function($){ $.extend( wp.Uploader.prototype, { success : function( file_attachment ){ console.log( file_attachment ); } }); ...


3

Have you tried returning an array instead? wp_send_json($an_array_of_your_vals); And then parse the array in the success function? success: function( data ) { var obj = jQuery.parseJSON(data); if( obj.arg_1 ) { $('selector').append( obj.content ); } else if( obj.arg_2 ) { $('other_selector').append( obj.content ); } ...


3

Try this code in your complete callback of the load function: $(".postbox_wrapper").load( jQuery(this).attr("href") + " .postbox_wrapper", function(response, status, xhr) { // complete callback // create a empty div var div = document.createElement('div'); // fill div with response div.innerHTML = response; ...


3

While your answer is very interesting and I like it, I still want to post another proposal, just let you have another choice :) IMHO, if the data contains only simple fields, like: array( 'name' => 'my name', 'address' => 'my address', 'phone' => '01234', ); then you can use the code below: add_filter( 'wpse63692_example_filter', ...


3

<?php function modified_post_gallery( $blank = NULL, $attr ) { echo '<pre>'; print_r( $attr ); echo '</pre>'; } add_filter( 'post_gallery', 'modified_post_gallery', 10, 2); ?> In media.php it shows the filter like this: // Allow plugins/themes to override the default gallery template. $output = ...


3

Your url should be pointing to admin-ajax.php echo admin_url('admin-ajax.php');


3

Short answer: no. Long answer: also no. Actions don't work that way. Edit: To elaborate and make your question totally generic: function foo() { bar(); return 1; } function bar() { // stuff } There is nothing you can put in stuff that will prevent a call to foo() from returning 1, other than halting script execution entirely with die or exit. ...


3

In your update_count_callback function do a check for $post->post_status and don't increment your count if post_status is not private. See this excellent answer on writing a custom update_count_callback callback function. Edit: Misread the question. To override the existing default for the category taxonomy you can create a function that overrides the ...


2

If you have a look at function do_meta_boxes() in wp-admin/includes/template.php then you'll see this line close to the end of the function: call_user_func($box['callback'], $object, $box); That calls the callback function and provides the two arguments. The $box argument holds all the information about the metabox, like ID, title, callback function. In ...


2

The last optional $args argument the you can pass to add_settings_fields() is passed to callback. So it seems you can use same callback just fine. Hope I am right because I just stumbled onto this two minutes ago because of discussion in chat. :) PS looked through code and it's indeed relatively recent, before ~2.9 arguments weren't passed.


2

Solution : hover on the title bar of your widget, then click configure Don't ask me why this works like this but it does.


2

$post_id = wp_insert_post( $arg ); #returns post ID $permalink = get_permalink( $post_id ); #returns the permalink Codex: http://codex.wordpress.org/Function_Reference/wp_insert_post


2

You can only return one chunk of data from a function. That is a PHP enforced rule. If you need to return multiple pieces of data you need to return an array or an object. With filters, though, you can't just decide what to return. You have to return what the filter is meant to return. For example, the_content callbacks need to return a string. Returning a ...


2

You can’t. Create a function that loads that file: function load_admin_page_file() { require 'admin-members.php'; } Then use that function name as callback argument. In PHP 5.3 you can use a lambda: add_menu_page( 'Members', 'Members', 'manage_options', 'members', function() { require 'admin-members.php'; } );


2

Programming and machines As machines are "stupid", they need to be programmed. And programming languages don't work like languages spoken by humans as programs/machines as they can't interpret what the human thinks. They need a clear and unique advice what and when to something we order them. If you for e.g. define the function getBlock() twice, the machine ...


2

This is correct: $control = $setting->manager->get_control($setting->id); $choices = $control->choices; However, in your example, $setting->id will be theme_oenology_options[name]. So, get_control('theme_oenology_options[name]') will return null because there's no control with that name. You gave the control the id of oenology_name ...


2

$this is not defined in the scope of a closure. Change it to: add_action('add_meta_boxes', function() use ($this) { add_meta_box('model', 'Parent', array($this,'parent_meta_box'), 'model', 'side', 'high'); }); Or better separate both and create a real method instead of a closure.


1

The reason my code was failing was due to it reaching a memory limit. I was adding a filter to the_content, and was calling another plugin's API (Custom Field Suite) to get some meta data that was of the WYSIWYG type. This type of field runs through the_content filter, so I was hitting an infinite loop. I couldn't find this out on WP Engine because they ...


1

I'd use a filter. You can remove this: if (function_exists('bf_new_defaults')) { return bf_new_defaults( $default_settings ); } else { return $default_settings; } and replace it with something like this: return apply_filters('bf_filter', $default_settings) The following is a truncated, proof of concept version of the code so you can see how ...


1

You could try something like this to test the CDN version first and then load conditionally based on if it is available or not: $get_the_url = 'http://netdna.bootstrapcdn.com/bootstrap/3.1.1/js/bootstrap.min.js'; $test_the_url = @fopen( $get_the_url,'r' ); if ( $test_the_url !== false ) { function load_external_bootstrap() { ...


1

Your first method doesn't work because you create a new instance of the class and try to remove the action from that new instance. That new instance you created is not the same instance that the action was added to, so it doesn't work. In the second example, you get the original instance that was created by the plugin, so removing the action from that ...


1

Here's a slightly modified version of your code snippet: add_action( 'login_head', [ 'WPSE_Admin', 'plugin_setup' ] ); class WPSE_Admin { public static function plugin_setup() { add_filter( 'login_headerurl', [ 'WPSE_Admin', 'the_logo_url' ] ); } public function the_logo_url() { return get_bloginfo('url'); } } The ...


1

@ciro is absolutely right about the server connecting not being an appropriate test for this. The point of the fallback is making sure the client can be served the document. There are countries that have Google blocked (as an example). If your web server is in California, but the visitor is in a country where Google is blocked, this PHP server-side call ...


1

Based on Stephen Harris answer I made my catch all handler accept a third argument, which is the shortcode name: /** * Handler for all shortcodes. * * @param array $args * @param NULL $content Not used. * @param string $shortcode Name of the current shortcode. * @return string */ public function shortcode_handler( $args = array (), $content = ...



Only top voted, non community-wiki answers of a minimum length are eligible