52 | | global $wp_meta_boxes; |
53 | | |
54 | | if ( is_string( $screen ) ) |
55 | | $screen = convert_to_screen( $screen ); |
56 | | |
57 | | if ( empty($wp_meta_boxes[$screen->id]) ) |
58 | | return; |
59 | | |
60 | | $hidden = get_hidden_meta_boxes($screen); |
61 | | |
62 | | foreach ( array_keys($wp_meta_boxes[$screen->id]) as $context ) { |
63 | | foreach ( array_keys($wp_meta_boxes[$screen->id][$context]) as $priority ) { |
64 | | foreach ( $wp_meta_boxes[$screen->id][$context][$priority] as $box ) { |
65 | | if ( false == $box || ! $box['title'] ) |
66 | | continue; |
67 | | // Submit box cannot be hidden |
68 | | if ( 'submitdiv' == $box['id'] || 'linksubmitdiv' == $box['id'] ) |
69 | | continue; |
70 | | $box_id = $box['id']; |
71 | | echo '<label for="' . $box_id . '-hide">'; |
72 | | echo '<input class="hide-postbox-tog" name="' . $box_id . '-hide" type="checkbox" id="' . $box_id . '-hide" value="' . $box_id . '"' . (! in_array($box_id, $hidden) ? ' checked="checked"' : '') . ' />'; |
73 | | echo "{$box['title']}</label>\n"; |
74 | | } |
75 | | } |
76 | | } |
| 52 | return; |
886 | | if ( isset( $wp_meta_boxes[ $this->id ] ) ) : ?> |
887 | | <div class="metabox-prefs"> |
888 | | <?php |
889 | | meta_box_prefs( $this ); |
| 859 | /* |
| 860 | * Render screen options in the admin bar |
| 861 | * |
| 862 | */ |
| 863 | function render_options( $parent, $wp_admin_bar ) { |
| 864 | $this->render_show_on_screen( $parent, $wp_admin_bar ); |
| 865 | $this->render_layout( $parent, $wp_admin_bar ); |
| 866 | $this->render_per_page( $parent, $wp_admin_bar ); |
| 867 | // @todo $this->_screen_settings |
| 868 | } |
891 | | if ( 'dashboard' === $this->id && current_user_can( 'edit_theme_options' ) ) { |
892 | | if ( isset( $_GET['welcome'] ) ) { |
893 | | $welcome_checked = empty( $_GET['welcome'] ) ? 0 : 1; |
894 | | update_user_meta( get_current_user_id(), 'show_welcome_panel', $welcome_checked ); |
895 | | } else { |
896 | | $welcome_checked = get_user_meta( get_current_user_id(), 'show_welcome_panel', true ); |
897 | | if ( 2 == $welcome_checked && wp_get_current_user()->user_email != get_option( 'admin_email' ) ) |
898 | | $welcome_checked = false; |
899 | | } |
900 | | echo '<label for="wp_welcome_panel-hide">'; |
901 | | echo '<input type="checkbox" id="wp_welcome_panel-hide"' . checked( (bool) $welcome_checked, true, false ) . ' />'; |
902 | | echo _x( 'Welcome', 'Welcome panel' ) . "</label>\n"; |
903 | | } |
904 | | ?> |
905 | | <br class="clear" /> |
906 | | </div> |
907 | | <?php endif; |
908 | | if ( $columns ) : |
909 | | if ( ! empty( $columns['_title'] ) ) : ?> |
910 | | <h5><?php echo $columns['_title']; ?></h5> |
911 | | <?php endif; ?> |
912 | | <div class="metabox-prefs"> |
913 | | <?php |
914 | | $special = array('_title', 'cb', 'comment', 'media', 'name', 'title', 'username', 'blogname'); |
| 870 | function render_show_on_screen( $parent, $wp_admin_bar ) { |
| 871 | global $wp_meta_boxes; |
923 | | if ( 'comments' == $column ) |
924 | | $title = __( 'Comments' ); |
925 | | $id = "$column-hide"; |
926 | | echo '<label for="' . $id . '">'; |
927 | | echo '<input class="hide-column-tog" name="' . $id . '" type="checkbox" id="' . $id . '" value="' . $column . '"' . checked( !in_array($column, $hidden), true, false ) . ' />'; |
928 | | echo "$title</label>\n"; |
| 876 | $columns = get_column_headers( $this ); |
| 877 | |
| 878 | if ( ! isset( $wp_meta_boxes[ $this->id ] ) && ( ! $columns || isset( $columns['_title'] ) ) ) |
| 879 | return; |
| 880 | |
| 881 | $wp_admin_bar->add_menu( array( |
| 882 | 'id' => 'show-on-screen', |
| 883 | 'parent' => $parent, |
| 884 | 'href' => '', |
| 885 | 'meta' => array( 'html' => '<h5>' . __( 'Show on screen' ) . '</h5>' ), |
| 886 | ) ); |
| 887 | |
| 888 | // Render meta box show/hide. |
| 889 | if ( isset( $wp_meta_boxes[ $this->id ] ) ) { |
| 890 | $hidden = get_hidden_meta_boxes($this); |
| 891 | |
| 892 | foreach ( array_keys($wp_meta_boxes[$this->id]) as $context ) { |
| 893 | foreach ( array_keys($wp_meta_boxes[$this->id][$context]) as $priority ) { |
| 894 | foreach ( $wp_meta_boxes[$this->id][$context][$priority] as $box ) { |
| 895 | if ( false == $box || ! $box['title'] ) |
| 896 | continue; |
| 897 | // Submit box cannot be hidden |
| 898 | if ( 'submitdiv' == $box['id'] || 'linksubmitdiv' == $box['id'] ) |
| 899 | continue; |
| 900 | $box_id = $box['id']; |
| 901 | $html = '<label for="' . $box_id . '-hide">' . |
| 902 | '<input class="hide-postbox-tog" name="' . $box_id . '-hide" type="checkbox" id="' . $box_id . '-hide" value="' . $box_id . '"' . (! in_array($box_id, $hidden) ? ' checked="checked"' : '') . ' />' . |
| 903 | "{$box['title']}</label>\n"; |
| 904 | $wp_admin_bar->add_menu( array( |
| 905 | 'id' => 'show-on-screen-' . $box_id, |
| 906 | 'parent' => $parent, |
| 907 | 'href' => '', |
| 908 | 'meta' => array( 'html' => $html ), |
| 909 | ) ); |
| 910 | } |
935 | | $this->render_screen_layout(); |
936 | | $this->render_per_page_options(); |
937 | | echo $this->_screen_settings; |
| 914 | if ( 'dashboard' === $this->id && current_user_can( 'edit_theme_options' ) ) { |
| 915 | if ( isset( $_GET['welcome'] ) ) { |
| 916 | $welcome_checked = empty( $_GET['welcome'] ) ? 0 : 1; |
| 917 | update_user_meta( get_current_user_id(), 'show_welcome_panel', $welcome_checked ); |
| 918 | } else { |
| 919 | $welcome_checked = get_user_meta( get_current_user_id(), 'show_welcome_panel', true ); |
| 920 | if ( 2 == $welcome_checked && wp_get_current_user()->user_email != get_option( 'admin_email' ) ) |
| 921 | $welcome_checked = false; |
| 922 | } |
| 923 | $html = '<label for="wp_welcome_panel-hide">' . |
| 924 | '<input type="checkbox" id="wp_welcome_panel-hide"' . checked( (bool) $welcome_checked, true, false ) . ' />' . |
| 925 | _x( 'Welcome', 'Welcome panel' ) . "</label>\n"; |
| 926 | $wp_admin_bar->add_menu( array( |
| 927 | 'id' => 'show-on-screen-' . $box_id, |
| 928 | 'parent' => $parent, |
| 929 | 'href' => '', |
| 930 | 'meta' => array( 'html' => $html ), |
| 931 | ) ); |
| 932 | } |
| 933 | } |
939 | | ?> |
940 | | <div><?php wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false ); ?></div> |
941 | | </form> |
942 | | </div> |
943 | | <?php |
| 935 | // Render column show/hide. |
| 936 | if ( $columns ) { |
| 937 | $hidden = get_hidden_columns( $this ); |
| 938 | |
| 939 | if ( ! empty( $columns['_title'] ) ) { |
| 940 | echo '<h5>' . $columns['_title'] . '</h5>'; |
| 941 | } |
| 942 | |
| 943 | $special = array( '_title', 'cb', 'comment', 'media', 'name', 'title', 'username', 'blogname' ); |
| 944 | |
| 945 | foreach ( $columns as $column => $title ) { |
| 946 | // Can't hide these for they are special |
| 947 | if ( in_array( $column, $special ) ) |
| 948 | continue; |
| 949 | if ( empty( $title ) ) |
| 950 | continue; |
| 951 | |
| 952 | if ( 'comments' == $column ) |
| 953 | $title = __( 'Comments' ); |
| 954 | $id = "$column-hide"; |
| 955 | $html = '<label for="' . $id . '">' . |
| 956 | '<input class="hide-column-tog" name="' . $id . '" type="checkbox" id="' . $id . '" value="' . $column . '"' . checked( !in_array($column, $hidden), true, false ) . ' />' . |
| 957 | "$title</label>\n"; |
| 958 | $wp_admin_bar->add_menu( array( |
| 959 | 'id' => 'show-on-screen-' . $column, |
| 960 | 'parent' => $parent, |
| 961 | 'href' => '', |
| 962 | 'meta' => array( 'html' => $html ), |
| 963 | ) ); |
| 964 | } |
| 965 | } |
946 | | /** |
947 | | * Render the option for number of columns on the page |
948 | | * |
949 | | * @since 3.3.0 |
950 | | */ |
951 | | function render_screen_layout() { |
| 968 | function render_layout( $parent, $wp_admin_bar ) { |
| 969 | // Back compat for plugins using the filter instead of add_screen_option() |
| 970 | $columns = apply_filters( 'screen_layout_columns', array(), $this->id, $this ); |
| 971 | |
| 972 | if ( ! empty( $columns ) && isset( $columns[ $this->id ] ) ) |
| 973 | $this->add_option( 'layout_columns', array('max' => $columns[ $this->id ] ) ); |
| 974 | |
| 975 | if ( $this->get_option( 'layout_columns' ) ) { |
| 976 | $this->columns = (int) get_user_option("screen_layout_$this->id"); |
| 977 | |
| 978 | if ( ! $this->columns && $this->get_option( 'layout_columns', 'default' ) ) |
| 979 | $this->columns = $this->get_option( 'layout_columns', 'default' ); |
| 980 | } |
| 981 | $GLOBALS[ 'screen_layout_columns' ] = $this->columns; // Set the global for back-compat. |
| 982 | |
958 | | ?> |
959 | | <h5 class="screen-layout"><?php _e('Screen Layout'); ?></h5> |
960 | | <div class='columns-prefs'><?php |
961 | | _e('Number of Columns:'); |
962 | | for ( $i = 1; $i <= $num; ++$i ): |
963 | | ?> |
964 | | <label class="columns-prefs-<?php echo $i; ?>"> |
965 | | <input type='radio' name='screen_columns' value='<?php echo esc_attr( $i ); ?>' |
966 | | <?php checked( $screen_layout_columns, $i ); ?> /> |
967 | | <?php echo esc_html( $i ); ?> |
968 | | </label> |
969 | | <?php |
970 | | endfor; ?> |
971 | | </div> |
972 | | <?php |
| 989 | $wp_admin_bar->add_menu( array( |
| 990 | 'id' => 'column-layout', |
| 991 | 'parent' => $parent, |
| 992 | 'href' => '', |
| 993 | 'meta' => array( 'html' => '<h5>' . __( 'Column Layout' ) . '</h5>' ), |
| 994 | ) ); |
| 995 | |
| 996 | for ( $i = 1; $i <= $num; ++$i ) { |
| 997 | $html = '<label class="columns-prefs-' . $i . '">' . |
| 998 | "<input type='radio' name='screen_columns' value='" . $i . "'" . |
| 999 | checked( $screen_layout_columns, $i, false ) . '/>' . |
| 1000 | esc_html( $i ) . |
| 1001 | '</label>'; |
| 1002 | |
| 1003 | $wp_admin_bar->add_menu( array( |
| 1004 | 'id' => 'column-layout-' . $i, |
| 1005 | 'parent' => $parent, |
| 1006 | 'href' => '', |
| 1007 | 'meta' => array( 'html' => $html ), |
| 1008 | ) ); |
| 1009 | } |
1010 | | ?> |
1011 | | <div class="screen-options"> |
1012 | | <?php if ( $per_page_label ) : ?> |
1013 | | <input type="number" step="1" min="1" max="999" class="screen-per-page" name="wp_screen_options[value]" |
1014 | | id="<?php echo esc_attr( $option ); ?>" maxlength="3" |
1015 | | value="<?php echo esc_attr( $per_page ); ?>" /> |
1016 | | <label for="<?php echo esc_attr( $option ); ?>"> |
1017 | | <?php echo esc_html( $per_page_label ); ?> |
1018 | | </label> |
1019 | | <?php endif; |
| 1050 | $wp_admin_bar->add_menu( array( |
| 1051 | 'id' => 'per-page', |
| 1052 | 'parent' => $parent, |
| 1053 | 'href' => '', |
| 1054 | 'meta' => array( 'html' => '<h5>' . __( 'Items Per Page' ) . '</h5>' ), |
| 1055 | ) ); |
1021 | | echo get_submit_button( __( 'Apply' ), 'button', 'screen-options-apply', false ); ?> |
1022 | | <input type='hidden' name='wp_screen_options[option]' value='<?php echo esc_attr($option); ?>' /> |
1023 | | </div> |
1024 | | <?php |
| 1057 | if ( $per_page_label ) { |
| 1058 | $html = '<input type="number" step="1" min="1" max="999" class="screen-per-page" name="wp_screen_options[value]" |
| 1059 | id="' . esc_attr( $option ) . '" maxlength="3" value="' . esc_attr( $per_page ) . '" />' . |
| 1060 | '<label for="' . esc_attr( $option ) . '">' . |
| 1061 | esc_html( $per_page_label ) . |
| 1062 | '</label>'; |
| 1063 | $wp_admin_bar->add_menu( array( |
| 1064 | 'id' => 'per-page-1', |
| 1065 | 'parent' => $parent, |
| 1066 | 'href' => '', |
| 1067 | 'meta' => array( 'html' => $html ), |
| 1068 | ) ); |
| 1069 | } |
| 1070 | |
| 1071 | $html = get_submit_button( __( 'Apply' ), 'button', 'screen-options-apply', false ) . |
| 1072 | "<input type='hidden' name='wp_screen_options[option]' value='" . esc_attr($option) . "' />"; |
| 1073 | |
| 1074 | $wp_admin_bar->add_menu( array( |
| 1075 | 'id' => 'per-page-submit', |
| 1076 | 'parent' => $parent, |
| 1077 | 'href' => '', |
| 1078 | 'meta' => array( 'html' => $html ), |
| 1079 | ) ); |