Get section of input passed to the sanitize_callback

Unfortunately if you look at the source the only thing that happens there is: add_filter( “sanitize_option_{$option_name}”, $sanitize_callback ); There is no opportunity to pass along or retrieve any extra information. On a larger scale I would say if you need section-specific sanitize then use section-specific callbacks. Even if considerable parts are shared with class based … Read more

Clean way to initialize plugin in newly-added site when plugin has been network activated?

After looking through Make WordPress, it looks like this is a known issue that won’t be fixed due to scalability concerns with large networks. That same issue linked above recommends doing exactly the solution discussed above. Specifically, that would look something like this: public static function 145561_activate_new_blog($blog_id) { if (is_plugin_active_for_network(plugin_basename(__FILE__))) { // do activation for … Read more

WP_NAV_MENU filter targets all menus

You could try the following code snippet to override the primary menu: /** * Override the primary menu. * * @param string $nav_menu The HTML content for the navigation menu. * @param array $args Array of wp_nav_menu() arguments. * @return string $nav_menu */ function wpse_150003( $nav_menu, $args ) { //Override the primary menu: if( ‘primary’ … Read more

Ajax +wordpress onClick link redirect to new page and create html content

I see two things. You’re missing an action call – you need add_action( ‘wp_ajax_render_admin_charts_page’, ‘render_admin_charts_page’ ); add_action(‘wp_ajax_nopriv_render_admin_charts_page’, ‘render_admin_charts_page’); Plus, from looking at your render_admin_charts_page() you need to change your json dataType to html. Your charts function is outputting html so all you need to do is output it; your alert() should contain all the html … Read more

Adding an external stylesheet to a plugin

I’m assuming your plugin is working, you just don’t get the stylesheet stuff to work? In that case, you can use the wp_enqueue_scripts action. http://codex.wordpress.org/Function_Reference/wp_enqueue_style#Using_a_Hook For usage with a stylesheet in the pluginfolder, you can use it like this: function my_plugin_name_scripts() { wp_enqueue_style( ‘my-plugin-custom-styles’, plugins_url(‘custom-styles.css’ , __FILE__ ) ); } add_action( ‘wp_enqueue_scripts’, ‘my_plugin_name_scripts’ ); Happy … Read more

How to make a cronjob type plugin

Yes, you can make a plugin. Following is the way to add cron job functionality in WordPress plugin. http://codex.wordpress.org/Function_Reference/wp_schedule_event http://codex.wordpress.org/Function_Reference/wp_cron However, please note that this does not provide a real (system based) cron. It requires at least someone to visit your site, so that the functions keep on executing periodically.