Tag Info

Hot answers tagged

4

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

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


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

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


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

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

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

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


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

$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

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


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

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

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


1

I'm assuming $settings is an assigned variable elsewhere in your code? If so, then ya gotta globalise it son (variable scope in PHP): function outputFavIcon() { global $settings; ?> And spell it right too ;) <?php if ( isset ( $settings['generel_settings' /* <- typo? */]['fav_icon'] ) ) {


1

This is what I've found so far. The trick is, that I'm using a non existent 2nd argument named $recursive to determine if I'm in a recursive loop or not. The default value is false, so the $is_multiple loop gets triggered. I'm then passing a true to the function call, to disallow a loop through possibly present sub-sub-arrays. The only reason why this is ...


1

Sometimes an example says more than a thousand words. Here's a small plugin that will guide you: <?php ! defined( 'ABSPATH' ) AND exit; /** * Plugin Name: (#65981) »kaiser« Meta Box example * Plugin URI: http://goo.gl/ls6Q6 * Description: Example showing how to add a meta box with callback args * Author: Franz Josef Kaiser * Author URI: ...


1

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


1

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


1

Are you sure you have created that menu and associated it with with "secondary" menu location? Just asking...


1

EDIT: I found several problems with your method. This is how it should be done for your case, I went ahead and rewrote some things. function my_button() { echo "<script type = 'text/javascript'> jQuery( document ).ready( function() { jQuery('input.sendajax').click( function() { var sendData = { action: ...


1

Do not use different callbacks, use the the sixth parameter for add_settings_field() instead. That is an array, and you can pass any data to the callback here. Example: foreach( $theOptions as $k => $v ) { add_settings_field( $k, $v, 'my_callback', $the_options, $the_group, array ( ...


1

Hi @Loni Huff: Your Code, Reformatted: It appear you are trying to call your callback with call_user_func() instead of just passing it. Reformatting your code, this is what you have: add_settings_section( 'expansion_' . $row->expansion_id, '', call_user_func(array(&$this, 'display_expansion'), $row->expansion), 'warpress_progression' ...



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