| 938 | | // If a core box was previously added or removed by a plugin, don't add. |
| 939 | | if ( 'core' == $priority ) { |
| 940 | | // If core box previously deleted, don't add |
| 941 | | if ( false === $wp_meta_boxes[$page][$a_context][$a_priority][$id] ) |
| | 925 | foreach ( $screen as $screen ) { |
| | 926 | if ( empty( $screen ) ) { |
| | 927 | $screen = get_current_screen(); |
| | 928 | } elseif ( is_string( $screen ) ) { |
| | 929 | $screen = convert_to_screen( $screen ); |
| | 930 | } |
| | 931 | |
| | 932 | if ( ! isset( $screen->id ) ) |
| | 933 | return; |
| | 934 | |
| | 935 | $page = $screen->id; |
| | 936 | |
| | 937 | if ( !isset($wp_meta_boxes[$page]) ) |
| | 938 | $wp_meta_boxes[$page] = array(); |
| | 939 | if ( !isset($wp_meta_boxes[$page][$context]) ) |
| | 940 | $wp_meta_boxes[$page][$context] = array(); |
| | 941 | |
| | 942 | foreach ( array_keys($wp_meta_boxes[$page]) as $a_context ) { |
| | 943 | foreach ( array('high', 'core', 'default', 'low') as $a_priority ) { |
| | 944 | if ( !isset($wp_meta_boxes[$page][$a_context][$a_priority][$id]) ) |
| | 945 | continue; |
| | 946 | |
| | 947 | // If a core box was previously added or removed by a plugin, don't add. |
| | 948 | if ( 'core' == $priority ) { |
| | 949 | // If core box previously deleted, don't add |
| | 950 | if ( false === $wp_meta_boxes[$page][$a_context][$a_priority][$id] ) |
| | 951 | return; |
| | 952 | // If box was added with default priority, give it core priority to maintain sort order |
| | 953 | if ( 'default' == $a_priority ) { |
| | 954 | $wp_meta_boxes[$page][$a_context]['core'][$id] = $wp_meta_boxes[$page][$a_context]['default'][$id]; |
| | 955 | unset($wp_meta_boxes[$page][$a_context]['default'][$id]); |
| | 956 | } |
| 948 | | return; |
| | 959 | // If no priority given and id already present, use existing priority |
| | 960 | if ( empty($priority) ) { |
| | 961 | $priority = $a_priority; |
| | 962 | // else if we're adding to the sorted priority, we don't know the title or callback. Grab them from the previously added context/priority. |
| | 963 | } elseif ( 'sorted' == $priority ) { |
| | 964 | $title = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['title']; |
| | 965 | $callback = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['callback']; |
| | 966 | $callback_args = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['args']; |
| | 967 | } |
| | 968 | // An id can be in only one priority and one context |
| | 969 | if ( $priority != $a_priority || $context != $a_context ) |
| | 970 | unset($wp_meta_boxes[$page][$a_context][$a_priority][$id]); |
| 950 | | // If no priority given and id already present, use existing priority |
| 951 | | if ( empty($priority) ) { |
| 952 | | $priority = $a_priority; |
| 953 | | // else if we're adding to the sorted priority, we don't know the title or callback. Grab them from the previously added context/priority. |
| 954 | | } elseif ( 'sorted' == $priority ) { |
| 955 | | $title = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['title']; |
| 956 | | $callback = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['callback']; |
| 957 | | $callback_args = $wp_meta_boxes[$page][$a_context][$a_priority][$id]['args']; |
| 958 | | } |
| 959 | | // An id can be in only one priority and one context |
| 960 | | if ( $priority != $a_priority || $context != $a_context ) |
| 961 | | unset($wp_meta_boxes[$page][$a_context][$a_priority][$id]); |