Hot answers tagged

10

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 ) ...


7

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 ...


6

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 ...


5

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 = ...


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

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 ); } }); ...


4

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

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


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

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 ...


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

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 ); } ...


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

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

You can use add_feed( $url, $callback ). Despite its name it sends a text/html Content-Type. Basic example: add_action( 'init', 'wpse_50841_register_extra_page' ); function wpse_50841_register_extra_page() { add_feed( 'wpse50841', 'wpse_50841_callback' ); } function wpse_50841_callback() { print '<p>It works!</p>'; } Visit 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

$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

I had the same problem, and here what works for me: function journal_check_cats_callback() { $options = get_option('journal_theme_blog_2_col'); $pag = journal_theme_blog_2_col; $_cats = get_terms( 'category' ); $html = ''; foreach ($_cats as $term) { $checked = in_array($term->term_id, $options) ? ...


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

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

$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.


2

I came up with two wrapper functions: function wp_enqueue_cdn_script( $handle, $src_cdn = false, $src_local = false, $deps = array(), $ver = false, $in_footer = false ) { $cdnIsUp = get_transient( $handle . '_script_cdn_is_up' ); if ( $cdnIsUp ) { wp_enqueue_script( $handle, $src_cdn, $deps, $ver, $in_footer ); } else { ...


2

@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 ...


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

The is_single template tag takes an optional parameter and therefore does not work for an active callback. Try this instead: function callback_single() { return is_single(); } $wp_customize->add_section('section_template_single' , array( 'title' => __('Single Links', $this->text_domain), 'priority' => 10, ...


1

Personally I'd do it the same way, since it seems to be the only point where you can examine user input and validate it. Also, heavily borrowing from code sample in this excellent article: function wpPartValidate_settings( $input ) { if ( check_admin_referer( 'wpPart_nonce_field', 'wpPart_nonce_verify_adm' ) ) { // Create our array for storing the ...


1

Oh I found ! $post_id = wp_insert_post($arg); // return post ID



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