How to block access to certain WordPress pages using a snippet

Try this, assuming that job_posting_access is a valid hook defines by some plugin: add_action( ‘job_posting_access’, function() { // $pages is Page ID, title, slug, or array of these for which access is restricted $pages = ( array (‘page 1’, 42, ‘page-2′) ); if ( ! current_user_can( ’employer’ ) && is_page( $pages ) ) wp_die(‘<div class=”job-manager-error”>Sorry, … Read more

Settings Fields not showing up in Submenu Page

The the code below: if(!class_exists(‘ce_add_scripts’)){ class ce_add_scripts{ function __construct(){ add_action(‘admin_init’, array(&$this,’ceas_admin_init’)); add_action(‘admin_menu’, array(&$this,’ceas_admin_menu’)); add_action(‘wp_head’, array(&$this,’ceas_wp_head’)); add_action(‘wp_footer’, array(&$this,’ceas_wp_footer’)); } function ceas_admin_menu(){ add_submenu_page( ‘tools.php’, ‘CE Add Scripts’, ‘CE Add Scripts’, ‘update_plugins’, ‘ceas_menu_page’, array(&$this,’ceas_page_callback’) ); } function ceas_admin_init(){ $args= array( ‘type’=>’string’, ‘default’=>NULL,); register_setting( ‘ceas_options’, ‘ceas_main_settings’, $args); add_settings_section( ‘ceas_options_section’, ‘Insert Scripts to Head or Footer’, array(&$this,’ceas_section_display’), ‘ceas_menu_page’); add_settings_field( ‘ceas_options_field_0’, … Read more

Add spacebar in WP List Table Search

function bulk_search() { $redirect_to = add_query_arg( array( ‘s’ => urlencode($_POST[‘s’]) ), $_POST[‘_wp_http_referer’]); wp_redirect( $redirect_to ); exit(); } Realised by adding urlencode() function would do.

Only return taxonomies that are linked to a category & product

This will find all terms in custom taxonomy underkategorier and then will show terms with post from chosen category. $taxonomies = get_taxonomies(array(‘name’=>’underkategorier’),’object’); foreach($taxonomies as $taxonomy) { $terms = get_terms( $taxonomy->name, ‘orderby=count&hide_empty=0’ ); foreach($terms as $term) { $wpq = array (‘taxonomy’=>’underkategorier’,’term’=>$term->slug, “cat”=>10); $myquery = new WP_Query ($wpq); $article_count = $myquery->post_count; echo $term->name.’ ‘.$article_count; //with empty ones … Read more