is_customize_preview() like function to check if Customizer “Live Preview” in JavaScript

you can just check for the customize object, but if you absolutely need a conditional statement to determine whatever it is you need, you can do something like this: jQuery( function( $ ) { // set var var in_customizer = false; // check for wp.customize return boolean if ( typeof wp !== ‘undefined’ ) { … Read more

Access Plugin data from Functions.php

Your syntax is slightly off in a few places. I’ll try and let the code explain: function wpse_199498_meta_to_table( $post_id, $post ) { // Use the second argument of our hook, which is the post object if ( $post->post_type !== ‘festival-event’ ) return; global $wpdb; // Don’t need to use $_POST, just use the functions as … Read more

Don’t delete a page if it holds users

It gives an array with objects. So in_array() won’t find anything, you have to convert it before. After you get the results from wbdb: $employees_array = array(); foreach($employees as $employee) { $employees_array[] = $employee->meta_value; } if(in_array($company, $employees_array)) { … }

Is it OK to include files using ABSPATH?

get_home_path() only works when WP admin scripts are loaded. ABSPATH is defined in wp-config.php so works anytime after the config file is loaded, so it should be totally fine for your use. It is set to the dirname(__FILE__) + trailing slash of wp-load.php (same location as e.g. wp-config.php). dirname here returns the absolute path where … Read more

How do I customize my wordpress Admin Area?

You can remove dashboard widgets/metaboxes using the following action, wp_dashboard_setup: Example 1 function remove_dashboard_widgets() { global $wp_meta_boxes; $wp_meta_boxes[‘dashboard’][‘normal’][‘core’] = array(); $wp_meta_boxes[‘dashboard’][‘side’][‘core’] = array(); } add_action(‘wp_dashboard_setup’, ‘remove_dashboard_widgets’, 100); Also there is the more specific core function, remove_meta_box() which can be used in the same way: Example 2 function remove_dashboard_widgets() { remove_meta_box( ‘dashboard_right_now’, ‘dashboard’, ‘normal’); remove_meta_box( ‘dashboard_activity’, … Read more