Articles of callbacks

Problem with Class, Filters and Callbacks

according to this Callback example if I’m referencing a method inside a class, I should use add_filter by specifying an array with 2 elements, first the object then the method. Here is my code: add_action (‘login_head’, array(‘Admin’, ‘plugin_setup’)); class Admin { public function plugin_setup() { add_filter(‘login_headerurl’, array($this, ‘the_logo_url’)); } private function the_logo_url() { return get_bloginfo(‘url’); […]

Retrieve post in AJAX Callback

I have a JS file that triggers a PHP callback file. The PHP file is supposed to work on the Post that is currently opened (wp-admin/post.php). I do not want the JS file to pass the post id though since that could be tampered with. Is there any way to repopulate the global $post or […]

Warning: call_user_func() expects parameter 1 to be a valid callback, function

I keep getting this error when. I am trying to insert a dashboard widget and I don’t know what’s causing the error. Warning: call_user_func() expects parameter 1 to be a valid callback, function ‘voguepay_woocommerce_payouts_dashboard_widget_display’ not found or invalid function name in C:\xampp\htdocs\9ja\wp-admin\includes\template.php on line 1037 here is the code to add the widget public function […]

register_settings callback function erases data

I have registered a setting with a callback function: register_setting( ‘my-plugin-settings-group’, ‘notification_email’, ’email_validation’ ) and callback function looks like: function email_validation($data) { if (null == $data) { add_settings_error( ‘requiredTextFieldEmpty’, ’empty’, ‘Notification Email cannot be empty’, ‘error’ ); } else { if (!is_email($data)){ add_settings_error( ‘requiredTextFieldEmpty’, ’empty’, ‘Notification Email is not valid email address’, ‘error’ ); } […]

How to use wp_send_json_error?

I’m having trouble understanding how wp_send_json_error works to return error messages. It works fine as long as none of the error conditions are met. But if there is an error, then nothing gets returned. How do I return the error messages set in wp_send_json_error() when there is an error? See my code: function submit_youtube_callback() { […]

Callback After WordPress Customizer Complete Loading

I’m facing a problem and it is that I’m trying to select textarea inside text widget, but problem is customizer appends dynamically content inside it so I’m unable to select it. I have successfully selected list inside which widget content is: jQuery(‘[id^=”customize-control-widget_text”]’).each(function(){ var each_text_widget_id = jQuery(this).attr(‘id’); var textarea_inside_text_widget = $(“#”+ each_text_widget_id ).find(‘textarea’).attr(‘id’); // Not Working […]

Detect device change (desktop, tablet or mobile) in Customizer

In the Theme Customizer preview I am using Modernizr to include certain classes that change the page styles. If I understand it correctly, changing the device type to tablet or mobile only changes the window size but doesn’t trigger any callback or page reload. Right now, the only way I can think of is adding […]

Where is this function's callback getting its arguments from?

This might be better suited to Stack Overflow, thought I’d try here first though. I was walking through this tutorial by Justin Tadlock and encountered the function below being used as the callback argument for the add_meta_box function. My questions concern the parameters… function smashing_post_class_meta_box( $object, $box ) { wp_nonce_field( basename( __FILE__ ), ‘smashing_post_class_nonce’ ); […]

PHP Warning: call_user_func() expects parameter 1 to be a valid callback

Confused. Writing a plugin with which I have other callbacks working similarly fine. But when adding a meta box its failing on the callback with error: PHP Warning: call_user_func() expects parameter 1 to be a valid callback, first array member is not a valid class name or object Fairly standard error but I can’t work […]

Ajax insert or update data

I’ve been browsing through similar questions and have yet to get this functionality to work. I’m tracking the progress a user makes an embedded vimeo video and insert data or update data. JS on the post page: $.ajax({ type: ‘POST’, dataType: ‘json’, url: ajaxurl, data: { ‘action’: ‘vimeo_progress’, ‘progress_percent’: progress, ‘progress_seconds’: seconds, ‘course_id’: courseID }, […]