Created
August 21, 2019 02:43
-
-
Save wpmudev-sls/e69b9eb3151ffbb37f055ab5882beb67 to your computer and use it in GitHub Desktop.
Move SmartCrawl Meabox to bottom
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
/** | |
* Plugin Name: [SmartCrawl Pro] - Move SmartCrawl Meabox to bottom | |
* Description: [SmartCrawl Pro] - Move SmartCrawl Meabox to bottom - 1135258637520550 | |
* Author: Thobk @ WPMUDEV | |
* Author URI: https://premium.wpmudev.org | |
* License: GPLv2 or later | |
*/ | |
if ( ! defined( 'ABSPATH' ) ) { | |
exit; | |
} | |
add_action( 'plugins_loaded', 'wpmudev_sc_move_smartcrawl_metabox_to_bottom_func', 100 ); | |
function wpmudev_sc_move_smartcrawl_metabox_to_bottom_func() { | |
if( defined('SMARTCRAWL_VERSION') && class_exists( 'Smartcrawl_Loader' ) ){ | |
// quit on admin screen | |
if( ! is_admin() || wp_doing_ajax() ) return; | |
add_action( 'admin_head-post.php', 'wpmudev_sc_move_smartcrawl_metabox_to_bottom_init' ); | |
add_action( 'admin_head-post-new.php', 'wpmudev_sc_move_smartcrawl_metabox_to_bottom_init' ); | |
function wpmudev_sc_move_smartcrawl_metabox_to_bottom_init(){ | |
$post_type = get_post_type(); | |
if( $post_type && 'attachment' !== $post_type ){ | |
add_filter( "get_user_option_meta-box-order_$post_type", 'wpmudev_sc_move_smartcrawl_metabox_to_bottom', 10, 2 ); | |
} | |
} | |
function wpmudev_sc_move_smartcrawl_metabox_to_bottom( $result ){ | |
$smartcrawl_mtb = 'wds-wds-meta-box'; | |
if( $result === false ){ | |
global $wp_meta_boxes; | |
$post_type = get_post_type(); | |
if( ! empty( $wp_meta_boxes[ $post_type ]['normal']['high'] ) ){ | |
$list_metaboxs = $wp_meta_boxes[ $post_type ]['normal']['high']; | |
if( isset( $list_metaboxs[ $smartcrawl_mtb ] ) && count( $list_metaboxs ) > 1 ){ | |
unset( $list_metaboxs[ $smartcrawl_mtb ] ); | |
$list_metaboxs = array_keys( $list_metaboxs ); | |
array_push($list_metaboxs, $smartcrawl_mtb ); | |
$result['normal'] = join(',', $list_metaboxs); | |
} | |
} | |
}elseif( ! empty( $result['normal'] ) ){ | |
$list_metaboxs = explode(',', $result['normal'] ); | |
$total_mtb = count( $list_metaboxs ) - 1; | |
if( $total_mtb ){ | |
if( ( $smartcrawl_mtb_pos = array_search( $smartcrawl_mtb, $list_metaboxs ) ) !== false && $smartcrawl_mtb_pos !== $total_mtb ){ | |
unset( $list_metaboxs[ $smartcrawl_mtb_pos ] ); | |
array_push($list_metaboxs, $smartcrawl_mtb ); | |
$result['normal'] = join(',', $list_metaboxs); | |
} | |
} | |
} | |
return $result; | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment