Adding items to menu not working in multisite - php

I have a custom code that it will automatically add the category to the menu in multisite. Lets say I have a category name "Cat1" then once I run my code this will automatically added to the menu. However 1 issue is that it will added if the blog is loggedin. I want to be added if it is not logging in.
Here is my code:
require( dirname(__FILE__) . '/wp-load.php' );
require_once( dirname(__FILE__) . '/wp-includes/ms-functions.php');
require_once( dirname(__FILE__) . '/wp-includes/user.php');
require_once( dirname(__FILE__) . '/wp-admin/includes/taxonomy.php');
require_once( dirname(__FILE__) . '/wp-admin/includes/nav-menu.php' );
$_nav_menu_selected_id = wp_update_nav_menu_object( 0, array('menu-name' => "Primary Menu") );
$test = array(
array(
'menu-item-db-id' => 0,
'menu-item-object-id' => 2,
'menu-item-object' => 'category',
'menu-item-parent-id' => 0,
'menu-item-type' => 'taxonomy',
'menu-item-title' => 'Rome',
'menu-item-url' => 'http://sub.example.com/love/',
'menu-item-target' => '',
'menu-item-classes' => '',
'menu-item-xfn' => '',
'menu-item-description' => ''
)
);
if($item_ids = wp_save_nav_menu_items( $_nav_menu_selected_id, $test )) {
foreach( $item_ids AS $single_item_id ) {
$my_post = array (
'ID' => $single_item_id,
'post_status' => 'publish',
'post_name' => $single_item_id
);
wp_update_post($my_post);
}
}
$menu_locations = array(
'main-menu' => $_nav_menu_selected_id,
'footer-menu' => $_nav_menu_selected_id
);
set_theme_mod( 'nav_menu_locations', $menu_locations );
If you run above example blog1.mysite.com it will added if I'm logging in on that blog. But if not they it will not added. However if I run it on www.mysite.com (not a subdomain) even if I'm not logging in it will added the category to the menu.

Related

how to limit cmb2 to specific page templates

I want cmb2 to be displayed in posts that have a movie template
I use this code :
$cmb_review = new_cmb2_box( array(
'id' => $prefix . 'metabox',
'title' => __( "My title", 'cmb2' ),
'object_types' => array( 'post'),
'show_on' => array( 'key' => 'page-template', 'value' => 'movie.php' )
));
but that doesn't work
I also tried this code but it didn't work :
function maybe_show($cmb_review ) {
$template = get_post_meta( $cmb_review ->object_id(), 'page-template', true );
if ( 'movie.php' === $template ) {
return true;
}
return false;
}
$cmb_review = new_cmb2_box( array(
'id' => $prefix . 'metabox',
'title' => __( "My title", 'cmb2' ),
'object_types' => array( 'post'),
'show_on_cb' => 'maybe_show'
));
Your meta box object type is post and is your template page for post too?
Make sure both match.

Adding new Icons to Visual Composer

I am trying to add a new font icon set to Visual Composer and although the name is appearing in the dropdown; No dropdown for the actual font icons are being loaded and I cannot figure out what's missing or wrong with my code below.
Any help would be much appreciated.
// Add new custom font to Font Family selection in icon box module
function reach_add_new_icon_set_to_iconbox( ) {
$param = WPBMap::getParam( 'vc_icon', 'type' );
$param['value'][__( 'Reach Icons', 'reach-rdp' )] = 'reach_icons';
vc_update_shortcode_param( 'vc_icon', $param );
}
add_filter( 'init', 'reach_add_new_icon_set_to_iconbox', 40 );
function reach_add_font_picker() {
vc_add_param( 'vc_icon', array(
'type' => 'iconpicker',
'heading' => esc_html__( 'Icon', 'reach-rdp' ),
'param_name' => 'icons_reach_icons',
'settings' => array(
'emptyIcon' => false,
'type' => 'reach_icons',
'iconsPerPage' => 20,
),
'dependency' => array(
'element' => 'icon_type',
'value' => 'reach_icons',
),
'group' => esc_html__( 'Icon', 'reach-rdp' ),
)
);
}
add_filter( 'vc_after_init', 'reach_add_font_picker', 40 );
function reach_vc_iconpicker_type_reach_icons( $icons ) {
// Add custom icons to array
$icons['Reach Icons'] = array(
array( "icon-arrow-left" => "Arrow Left" ),
);
// Return icons
return $icons;
}
add_filter( 'vc_iconpicker-type-reach_icons', 'reach_vc_iconpicker_type_reach_icons' );
/**
* Register Backend and Frontend CSS Styles
*/
add_action( 'vc_base_register_front_css', 'leadinjection_vc_iconpicker_base_register_css' );
add_action( 'vc_base_register_admin_css', 'leadinjection_vc_iconpicker_base_register_css' );
function leadinjection_vc_iconpicker_base_register_css(){
wp_register_style('reach_icons', get_stylesheet_directory_uri() . '/assets/css/reach-font.css');
}
/**
* Enqueue Backend and Frontend CSS Styles
*/
add_action( 'vc_backend_editor_enqueue_js_css', 'leadinjection_vc_iconpicker_editor_jscss' );
add_action( 'vc_frontend_editor_enqueue_js_css', 'leadinjection_vc_iconpicker_editor_jscss' );
function leadinjection_vc_iconpicker_editor_jscss(){
wp_enqueue_style( 'reach_icons' );
}
It looks like you do the most things correct, you just need to replace:
add_filter('init....)
to:
add_action('vc_after_init',....)
update:
Also you have a wrong param name in dependency.
it should be:
'element' => 'type',
And I also will recommend to use the weight attribute to make sorting better:
function reach_add_new_icon_set_to_iconbox( ) {
$param = WPBMap::getParam( 'vc_icon', 'type' );
$param['value'][__( 'Reach Icons', 'reach-rdp' )] = 'reach_icons';
$param['weight'] = 90;
vc_update_shortcode_param( 'vc_icon', $param );
}
and
function reach_add_font_picker() {
vc_add_param( 'vc_icon', array(
'type' => 'iconpicker',
'heading' => esc_html__( 'Icon', 'reach-rdp' ),
'param_name' => 'icons_reach_icons',
'settings' => array(
'emptyIcon' => false,
'type' => 'reach_icons',
'iconsPerPage' => 20,
),
'weight' => 80,
'dependency' => array(
'element' => 'type',
'value' => 'reach_icons',
),
)
);
}
I needed to achieve exactly the same thing - although the icon set I'm adding is selection of icons from the Font Awesome Pro set. Using the answer that almost worked above, here is my fully working version. This is tested and working in version 5.5.2 of WPBakery. I hope this helps someone!
// In the 'Icon library' dropdown for an icon content type, add a new family of icons.
function fapro_add_to_iconbox() {
$param = WPBMap::getParam( 'vc_icon', 'type' );
$param['value'][ __( 'FontAwesome Pro icons', 'js_composer' ) ] = 'fapro';
vc_update_shortcode_param( 'vc_icon', $param );
}
add_filter( 'vc_after_init', 'fapro_add_to_iconbox', 40 );
// This adds a new parameter to the vc_icon content block.
// This parameter is an icon_picker element,
// that displays when fapro is picked from the dropdown.
function fapro_add_font_picker() {
$settings = array(
'type' => 'iconpicker',
'heading' => __( 'Icon', 'js_composer' ),
'param_name' => 'icon_fapro',
'settings' => array(
'emptyIcon' => false,
'type' => 'fapro',
'iconsPerPage' => 20,
),
'dependency' => array(
'element' => 'type',
'value' => 'fapro',
),
'weight' => '1',
'description' => __( 'Select icon from library.', 'js_composer' ),
);
vc_add_param( 'vc_icon', $settings );
}
add_filter( 'vc_after_init', 'fapro_add_font_picker', 50 );
// Add all the icons we want to display in our font family.
function vc_iconpicker_type_fapro( $icons ) {
// Add custom icons to array.
$fapro_icons = array(
array( 'far fa-bacon' => 'Bacon' ),
array( 'fas fa-hamburger' => 'Hamburger' ),
);
// Return icons.
return $fapro_icons;
}
add_filter( 'vc_iconpicker-type-fapro', 'vc_iconpicker_type_fapro' );
// Enqueue the CSS file so that the icons display in the backend editor.
function enqueue_fapro_font() {
wp_enqueue_style( 'agilechilli-font-awesome', 'https://pro.fontawesome.com/releases/v5.7.2/css/all.css' );
}
add_action( 'vc_backend_editor_enqueue_js_css', 'enqueue_fapro_font' );

On plugin activation, create page and set template?

I'm creating a plugin that I want to create a page when it is activated and also set the template that it's using.
I've done the first part in that on activation it creates the page, how can I set the template? This is what I've attempted but it just picks the default template:
if ( $theme_file = locate_template( array( 'contact.php' ) ) ) {
$template = $theme_file;
} else {
$template = plugin_dir_path( __FILE__ ) . 'templates/contact.php';
}
//post status and options
$post = array(
'comment_status' => 'closed',
'ping_status' => 'closed' ,
'post_author' => 1,
'post_date' => date('Y-m-d H:i:s'),
'post_name' => 'Contact',
'post_status' => 'publish' ,
'post_title' => 'Contact',
'post_type' => 'page',
'page_template' => $template
);
wp_insert_post( $post );
add_filter( 'page_template', 'wp_page_template' );
function wp_page_template( $page_template )
{
if ( is_page( 'Contact' ) ) {
$page_template = plugin_dir_path( __FILE__ ) . 'templates/contact.php';
}
return $page_template;
}
try this...

WP custom_pre_get_posts breaks theme

I added this code weeks ago, but it suddenly stopped working last night, how could that be? It works fine on a local server, but not on a shared host. Local is running PHP 5.5.3 and host was running 5.4, but I put in a request to upgrade that specific subdomain to 5.5 just now in case that was at play.
Working with a child theme. The parent theme creates a custom post type called Portfolio, with the slug for all posts in it as /portfolio-item/. In my child theme, I added two things: 1. A new custom post type called Hidden Pages, and I used a code I found online that removes the slug, so it's just domain.com/page-name. 2. I added more code referring to the Portfolio type, which also removes the slug.
Everything was working perfectly, but all of a sudden, all standard pages 404 (and are hidden on the backend, but not in the database, this is not a database problem!), and the Portfolio posts are magically moved to the blog (regular standard posts). If you comment out the custom_pre_get_posts line (132), the problem resolves. But the client needs the urls to be clean without the slug. So I do not want to leave it as-is.
Here is the functions.php for the child theme:
<?php
function evol_child_scripts() {
wp_enqueue_style( 'style', get_stylesheet_directory_uri() . '/stylesheets/css/style.css' );
}
add_action( 'wp_enqueue_scripts', 'evol_child_scripts' );
/*function codex_custom_init() {
$args = array(
'public' => true,
'label' => 'Hidden Pages'
);
register_post_type( 'hidden', $args );
}
add_action( 'init', 'codex_custom_init' );
*/
/**
* Register a custom post type but don't do anything fancy
*/
register_post_type( 'hidden', array( 'label' => 'Hidden Pages', 'public' => true, 'capability_type' => 'post', 'show_ui' => true, 'query_var' => true, 'supports' => array( 'title', 'editor', 'thumbnail' ) ) );
/**
* Remove the slug from published post permalinks. Only affect our CPT though.
*/
function vipx_remove_cpt_slug( $post_link, $post, $leavename ) {
if ( ! in_array( $post->post_type, array( 'hidden' ) )
|| 'publish' != $post->post_status )
return $post_link;
$post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link );
return $post_link;
}
add_filter( 'post_type_link', 'vipx_remove_cpt_slug', 10, 3 );
/**
* Some hackery to have WordPress match postname to any of our public
* post types. All of our public post types can have /post-name/ as
* the slug, so they better be unique across all posts. Typically core
* only accounts for posts and pages where the slug is /post-name/
*/
function vipx_parse_request_tricksy( $query ) {
// Only noop the main query
if ( ! $query->is_main_query() )
return;
// Only noop our very specific rewrite rule match
if ( 2 != count( $query->query )
|| ! isset( $query->query['page'] ) )
return;
// 'name' will be set if post permalinks are just post_name,
// otherwise the page rule will match
if ( ! empty( $query->query['name'] ) )
$query->set( 'post_type', array( 'post', 'hidden', 'page' ) );
}
add_action( 'pre_get_posts', 'vipx_parse_request_tricksy' );
function remove_search_filter () {
remove_filter( 'pre_get_posts', 'tr_search_filter' );
}
add_action( 'init', 'remove_search_filter');
function remove_icons() {
wp_dequeue_style( 'icons' );
}
add_action( 'wp_enqueue_scripts', 'remove_icons' );
function tr_widgets_init_2() {
if ( ot_get_option( 'tr_sidebars' ) ) :
$tr_sidebars = ot_get_option( 'tr_sidebars' );
foreach ( $tr_sidebars as $tr_sidebar ) {
register_sidebar( array(
'id' => $tr_sidebar["id"],
'name' => $tr_sidebar["title"],
'before_widget' => '<div class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h6 class="widget-title">',
'after_title' => '</h6>',
));
}
endif;
};
add_action( 'widgets_init', 'tr_widgets_init_2' );
add_filter('post_type_link','custom_post_type_link', 10, 3);
function custom_post_type_link($permalink, $post, $leavename) {
$url_components = parse_url($permalink);
$post_path = $url_components['path'];
$post_name = end((explode('/', trim($post_path, '/'))));
if(!empty($post_name)) {
switch($post->post_type) {
case 'portfolio':
$permalink = str_replace($post_path, '/' . $post_name . '/', $permalink);
break;
}
}
return $permalink;
}
function custom_pre_get_posts($query) {
global $wpdb;
if(!$query->is_main_query()) {
return;
}
$post_name = $query->get('name');
$post_type = $wpdb->get_var( $wpdb->prepare( 'SELECT post_type FROM ' . $wpdb->posts . ' WHERE post_name = %s LIMIT 1', $post_name ) );
switch($post_type) {
case 'portfolio':
$query->set('portfolio', $post_name);
$query->set('post_type', $post_type);
$query->is_single = true;
$query->is_page = false;
break;
}
return $query;
}
add_action('pre_get_posts','custom_pre_get_posts');
function fb_add_search_box ( $items, $args ) {
// only on primary menu
if( 'primary' === $args -> theme_location )
$items .= '<li class="menu-item menu-item-search">' . get_search_form( FALSE ) . '</li>';
return $items;
}
add_filter( 'wp_nav_menu_items', 'fb_add_search_box', 10, 2 );
// Callback function to insert 'styleselect' into the $buttons array
function my_mce_buttons_2( $buttons ) {
array_unshift( $buttons, 'styleselect' );
return $buttons;
}
// Register our callback to the appropriate filter
add_filter('mce_buttons_2', 'my_mce_buttons_2');
// Callback function to filter the MCE settings
function my_mce_before_init_insert_formats( $init_array ) {
// Define the style_formats array
$style_formats = array(
// Each array child is a format with it's own settings
array(
'title' => 'Image Text',
'block' => 'p',
'classes' => 'image-text',
),
array(
'title' => 'Image Text no Overlay',
'block' => 'p',
'classes' => 'image-text-2',
),
array(
'title' => 'w/ gray background',
'inline' => 'span',
'exact' => true,
'classes' => 'gray-background',
),
array(
'title' => 'w/ white background',
'inline' => 'span',
'exact' => true,
'classes' => 'white-background',
),
array(
'title' => 'Image Text no Indent',
'block' => 'p',
'classes' => 'image-text-3',
),
array(
'title' => 'Button',
'inline' => 'a',
'exact' => true,
'classes' => 'button small',
),
array(
'title' => 'Blog Image Caption',
'block' => 'p',
'classes' => 'caption',
),
array(
'title' => 'Signature',
'inline' => 'span',
'exact' => true,
'classes' => 'sign',
),
);
// Insert the array, JSON ENCODED, into 'style_formats'
$init_array['style_formats'] = json_encode( $style_formats );
return $init_array;
}
// Attach callback to 'tiny_mce_before_init'
add_filter( 'tiny_mce_before_init', 'my_mce_before_init_insert_formats' );
This is the parent functions.php:
<?php
/*----------------------------------------------------------------------------*/
/* Sets up theme defaults and registers support for various WordPress features.
/*----------------------------------------------------------------------------*/
function tr_theme_setup() {
load_theme_textdomain( 'themerain', get_template_directory() . '/languages' );
add_theme_support( 'automatic-feed-links' );
add_theme_support( 'html5', array( 'search-form', 'comment-form', 'comment-list' ) );
register_nav_menu( 'primary', 'Navigation Menu' );
add_theme_support( 'post-thumbnails' );
add_image_size( 'portfolio', 740, 540, true );
}
add_action( 'after_setup_theme', 'tr_theme_setup' );
/*----------------------------------------------------------------------------*/
/* Sets up the content width value based on the theme's design and stylesheet.
/*----------------------------------------------------------------------------*/
if ( ! isset( $content_width ) ) $content_width = 780;
/*----------------------------------------------------------------------------*/
/* Load Theme Options
/*----------------------------------------------------------------------------*/
add_filter( 'ot_show_pages', '__return_false' );
add_filter( 'ot_show_new_layout', '__return_false' );
add_filter( 'ot_theme_mode', '__return_true' );
load_template( trailingslashit( get_template_directory() ) . 'option-tree/ot-loader.php' );
load_template( trailingslashit( get_template_directory() ) . 'includes/theme-options.php' );
load_template( trailingslashit( get_template_directory() ) . 'includes/meta-boxes.php' );
load_template( trailingslashit( get_template_directory() ) . 'includes/theme-functions.php' );
/*----------------------------------------------------------------------------*/
/* Register Sidebars
/*----------------------------------------------------------------------------*/
function tr_widgets_init() {
register_sidebar( array(
'id' => 'sidebar',
'name' => 'Default Sidebar',
'before_widget' => '<div class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h6 class="widget-title">',
'after_title' => '</h6>',
));
register_sidebar( array(
'id' => 'footer-sidebar',
'name' => 'Footer Sidebar',
'before_widget' => '<div class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h6 class="widget-title">',
'after_title' => '</h6>',
));
if ( ot_get_option( 'tr_sidebars' ) ) :
$tr_sidebars = ot_get_option( 'tr_sidebars' );
foreach ( $tr_sidebars as $tr_sidebar ) {
register_sidebar( array(
'id' => $tr_sidebar["id"],
'name' => $tr_sidebar["title"],
'before_widget' => '<div class="widget %2$s">',
'after_widget' => '</div>',
'before_title' => '<h6 class="widget-title">',
'after_title' => '</h6>',
));
}
endif;
};
add_action( 'widgets_init', 'tr_widgets_init' );
/*----------------------------------------------------------------------------*/
/* Register and load CSS & jQuery
/*----------------------------------------------------------------------------*/
function tr_enqueue_scripts() {
wp_enqueue_style( 'style', get_stylesheet_uri() );
wp_enqueue_style( 'icons', get_template_directory_uri() . '/assets/css/icons.css' );
wp_enqueue_style( 'magnific', get_template_directory_uri() . '/assets/css/magnific-popup.css' );
wp_enqueue_script( 'jquery' );
wp_enqueue_script( 'custom', get_template_directory_uri() . '/assets/js/jquery.custom.js', 'jquery' );
wp_enqueue_script( 'flexslider', get_template_directory_uri() . '/assets/js/jquery.flexslider.min.js', 'jquery' );
wp_enqueue_script( 'isotope', get_template_directory_uri() . '/assets/js/jquery.isotope.min.js', 'jquery' );
wp_enqueue_script( 'magnific', get_template_directory_uri() . '/assets/js/jquery.magnific-popup.min.js', 'jquery' );
wp_enqueue_script( 'validation', get_template_directory_uri() . '/assets/js/jquery.validate.min.js', 'jquery' );
if ( is_singular() ) wp_enqueue_script( 'comment-reply' );
}
add_action( 'wp_enqueue_scripts', 'tr_enqueue_scripts' );
/*----------------------------------------------------------------------------*/
/* Load Widgets
/*----------------------------------------------------------------------------*/
include( "includes/widget-recent-projects.php" );
/*----------------------------------------------------------------------------*/
/* Configure Pagination
/*----------------------------------------------------------------------------*/
function tr_pagination() {
global $wp_query, $wp_rewrite;
$pages = '';
$total = 1;
$max = $wp_query->max_num_pages;
if ( ! $current = get_query_var( 'paged' ) ) $current = 1;
$args['base'] = str_replace( 999999999, '%#%', get_pagenum_link( 999999999 ) );
$args['total'] = $max;
$args['current'] = $current;
$args['end_size'] = 1;
$args['mid_size'] = 3;
$args['prev_text'] = '<i class="fa-angle-left"></i> Previous';
$args['next_text'] = 'Next <i class="fa-angle-right"></i>';
$args['type'] = 'list';
if ( $max > 1 ) echo '<div id="pagination">';
if ( $total == 1 && $max > 1 );
echo $pages . paginate_links( $args );
if ( $max > 1 ) echo '</div>';
}
/*----------------------------------------------------------------------------*/
/* Configure Excerpt
/*----------------------------------------------------------------------------*/
function new_excerpt_more( $more ) {
return ' ...';
}
add_filter( 'excerpt_more', 'new_excerpt_more' );
/*-----------------------------------------------------------------------------------*/
/* Configure Tag Cloud
/*-----------------------------------------------------------------------------------*/
function tag_cloud_filter($args = array()) {
$args['smallest'] = 12;
$args['largest'] = 12;
$args['unit'] = 'px';
return $args;
}
add_filter('widget_tag_cloud_args', 'tag_cloud_filter', 90);
/*----------------------------------------------------------------------------*/
/* Exclude Pages from Search
/*----------------------------------------------------------------------------*/
function tr_search_filter( $filter ) {
if ( $filter->is_search ) {
$filter->set( 'post_type', 'post' );
}
return $filter;
}
add_filter( 'pre_get_posts', 'tr_search_filter' );
/*----------------------------------------------------------------------------*/
/* Add Portfolio Post Types
/*----------------------------------------------------------------------------*/
function tr_portfolio() {
$labels = array(
'name' => 'Portfolio',
'singular_name' => 'Portfolio Item',
'add_new' => 'Add New',
'add_new_item' => 'Add New Portfolio Item',
'edit_item' => 'Edit Portfolio Item',
'new_item' => 'New Portfolio Items',
'view_item' => 'View Portfolio Item',
'search_items' => 'Search Portfolio Items',
'not_found' => 'No Portfolio Items found',
'not_found_in_trash' => 'No Portfolio Items found in Trash',
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'exclude_from_search' => false,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => 4,
'rewrite' => array( 'slug' => 'portfolio-item' ),
'supports' => array( 'title', 'editor', 'thumbnail' )
);
register_post_type( 'portfolio', $args );
register_taxonomy(
"portfolio-category", array( "portfolio" ), array(
"hierarchical" => true,
"label" => "Portfolio Categories",
"singular_label" => "Portfolio Categories",
"rewrite" => true,
"query_var" => true
)
);
}
add_action( 'init', 'tr_portfolio' );
/*----------------------------------------------------------------------------*/
/* Add Gallery Post Types
/*----------------------------------------------------------------------------*/
function tr_gallery() {
$labels = array(
'name' => 'Gallery',
'singular_name' => 'Gallery Item',
'add_new' => 'Add New',
'add_new_item' => 'Add New Gallery Item',
'edit_item' => 'Edit Gallery Item',
'new_item' => 'New Gallery Items',
'view_item' => 'View Gallery Item',
'search_items' => 'Search Gallery Items',
'not_found' => 'No Gallery Items found',
'not_found_in_trash' => 'No Gallery Items found in Trash',
'parent_item_colon' => ''
);
$args = array(
'labels' => $labels,
'public' => true,
'exclude_from_search' => true,
'publicly_queryable' => true,
'show_ui' => true,
'query_var' => true,
'capability_type' => 'post',
'hierarchical' => false,
'menu_position' => 4,
'rewrite' => array( 'slug' => 'gallery-item' ),
'supports' => array( 'title', 'thumbnail' )
);
register_post_type( 'gallery', $args );
register_taxonomy(
"gallery-category", array( "gallery" ), array(
"hierarchical" => true,
"label" => "Gallery Categories",
"singular_label" => "Gallery Categories",
"rewrite" => true,
"query_var" => true
)
);
}
add_action( 'init', 'tr_gallery' );
/*----------------------------------------------------------------------------*/
/* Add a Custom Taxonomy to the Post Class
/*----------------------------------------------------------------------------*/
function custom_portfolio_post_class( $classes, $class, $ID ) {
$taxonomy = 'portfolio-category';
$terms = get_the_terms( (int) $ID, $taxonomy );
if ( ! empty( $terms ) ) {
foreach ( (array) $terms as $order => $term ) {
if ( ! in_array( $term->slug, $classes ) ) {
$classes[] = $term->slug;
}
}
}
return $classes;
}
add_filter( 'post_class', 'custom_portfolio_post_class', 10, 3 );
function custom_gallery_post_class( $classes, $class, $ID ) {
$taxonomy = 'gallery-category';
$terms = get_the_terms( (int) $ID, $taxonomy );
if ( ! empty( $terms ) ) {
foreach ( (array) $terms as $order => $term ) {
if ( ! in_array( $term->slug, $classes ) ) {
$classes[] = $term->slug;
}
}
}
return $classes;
}
add_filter( 'post_class', 'custom_gallery_post_class', 10, 3 );
/*----------------------------------------------------------------------------*/
/* Register the Required Plugins
/*----------------------------------------------------------------------------*/
require_once dirname( __FILE__ ) . '/includes/plugin-activation.php';
function tr_register_required_plugins() {
$plugins = array(
array(
'name' => 'Rain Shortcodes',
'slug' => 'rain-shortcodes',
'source' => get_stylesheet_directory() . '/includes/plugins/rain-shortcodes.zip',
'required' => true,
'version' => '',
'force_activation' => false,
'force_deactivation' => false,
'external_url' => '',
)
);
$theme_text_domain = 'tgmpa';
$config = array(
'domain' => $theme_text_domain,
'default_path' => '',
'parent_menu_slug' => 'themes.php',
'parent_url_slug' => 'themes.php',
'menu' => 'install-required-plugins',
'has_notices' => true,
'is_automatic' => true,
'message' => '',
'strings' => array(
'page_title' => __( 'Install Required Plugins', $theme_text_domain ),
'menu_title' => __( 'Install Plugins', $theme_text_domain ),
'installing' => __( 'Installing Plugin: %s', $theme_text_domain ), // %1$s = plugin name
'oops' => __( 'Something went wrong with the plugin API.', $theme_text_domain ),
'notice_can_install_required' => _n_noop( 'This theme requires the following plugin: %1$s.', 'This theme requires the following plugins: %1$s.' ),
'notice_can_install_recommended' => _n_noop( 'This theme recommends the following plugin: %1$s.', 'This theme recommends the following plugins: %1$s.' ),
'notice_cannot_install' => _n_noop( 'Sorry, but you do not have the correct permissions to install the %s plugin. Contact the administrator of this site for help on getting the plugin installed.', 'Sorry, but you do not have the correct permissions to install the %s plugins. Contact the administrator of this site for help on getting the plugins installed.' ),
'notice_can_activate_required' => _n_noop( 'The following required plugin is currently inactive: %1$s.', 'The following required plugins are currently inactive: %1$s.' ),
'notice_can_activate_recommended' => _n_noop( 'The following recommended plugin is currently inactive: %1$s.', 'The following recommended plugins are currently inactive: %1$s.' ),
'notice_cannot_activate' => _n_noop( 'Sorry, but you do not have the correct permissions to activate the %s plugin. Contact the administrator of this site for help on getting the plugin activated.', 'Sorry, but you do not have the correct permissions to activate the %s plugins. Contact the administrator of this site for help on getting the plugins activated.' ),
'notice_ask_to_update' => _n_noop( 'The following plugin needs to be updated to its latest version to ensure maximum compatibility with this theme: %1$s.', 'The following plugins need to be updated to their latest version to ensure maximum compatibility with this theme: %1$s.' ),
'notice_cannot_update' => _n_noop( 'Sorry, but you do not have the correct permissions to update the %s plugin. Contact the administrator of this site for help on getting the plugin updated.', 'Sorry, but you do not have the correct permissions to update the %s plugins. Contact the administrator of this site for help on getting the plugins updated.' ),
'install_link' => _n_noop( 'Begin installing plugin', 'Begin installing plugins' ),
'activate_link' => _n_noop( 'Activate installed plugin', 'Activate installed plugins' ),
'return' => __( 'Return to Required Plugins Installer', $theme_text_domain ),
'plugin_activated' => __( 'Plugin activated successfully.', $theme_text_domain ),
'complete' => __( 'All plugins installed and activated successfully. %s', $theme_text_domain ),
'nag_type' => 'updated'
)
);
tgmpa( $plugins, $config );
}
add_action( 'tgmpa_register', 'tr_register_required_plugins' );
?>
When wp_debug is set to true, this returns:
Strict Standards: Only variables should be passed by reference in
[path redacted]/functions.php on line 97
This refers to this line:
$post_name = end(explode('/', trim($post_path, '/')));
This is still in the error log, but after a change, it is not there on the admin side, does that mean it's fixed?
Child theme code is from here: https://gist.github.com/stefanbc/6620151 and http://www.markwarddesign.com/2014/02/remove-custom-post-type-slug-permalink/
So, if anyone knows how to modify this file to revert everything back to working perfectly, that'd be great. We are days away from launch, actually. Eep. Thank you!
Problem is not with Wordpress as the error stated, It's all pure PHP. You should make a little change in that line (wrapping explode() with parenthesis):
$post_name = end((explode('/', trim($post_path, '/'))));
I could not find a solution to this problem given my level of PHP and not wanting to rewrite code that involves both a parent and child theme's functions. I ended up removing all code that attempted to remove the slug. I crossed my fingers and installed this outdated plugin and it worked. So for anyone for future reference, I suppose you can avoid code and just use this instead!
https://wordpress.org/plugins/remove-slug-from-custom-post-type/

WP Custom meta box for a specific page template

I have created a custom meta box using option tree framework. It is showing for every page. I want that it will show only for a specific page. How can i do that?
I have written this code to functions.php file
add_action( 'admin_init', 'custom_meta_boxes' );
function custom_meta_boxes() {
$latest_work = array(
'id' => 'latest_work',
'title' => 'latest-work Meta Box',
'desc' => '',
'pages' => array( 'page' ),
'context' => 'normal',
'priority' => 'high',
'fields' => array(
array(
'label' => 'latest-work',
'id' => 'latest-work',
'type' => 'text',
'desc' => 'Tell about your latest work',
'std' => '',
'rows' => '',
'post_type' => '',
'taxonomy' => '',
'class' => ''
)
)
);
ot_register_meta_box( $latest_work );
}
Please tell me how can i do that?
add_action( 'admin_menu', 'remove_post_meta_boxes' );
function remove_post_meta_boxes() {
// lets assume blog page has the id 23
// let's remove the meta box from blog
if( isset($_GET['post']) && $_GET['post'] == 23 ){
remove_meta_box( 'latest_work', 'page', 'normal' );
}
}
take a look for more information remove_meta_box()
Use the following.
$post_id = $_GET['post'] ? $_GET['post'] : $_POST['post_ID'] ;
// checks for post/page ID for example i have added 7
if ($post_id == '7'){
/.add_meta box code inside
}

Categories