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; |
| 852 | /* |
| 853 | * Render screen options in the admin bar |
| 854 | * |
| 855 | */ |
| 856 | function render_options( $parent, $wp_admin_bar ) { |
| 857 | $this->render_show_on_screen( $parent, $wp_admin_bar ); |
| 858 | $this->render_layout( $parent, $wp_admin_bar ); |
| 859 | $this->render_per_page( $parent, $wp_admin_bar ); |
| 860 | // @todo $this->_screen_settings |
| 861 | } |
| 862 | |
| 863 | function render_show_on_screen( $parent, $wp_admin_bar ) { |
| 864 | global $wp_meta_boxes; |
| 865 | |
| 866 | if ( ! $this->show_screen_options() ) |
| 867 | return; |
| 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"; |
| 881 | // Render meta box show/hide. |
| 882 | if ( isset( $wp_meta_boxes[ $this->id ] ) ) { |
| 883 | $hidden = get_hidden_meta_boxes($this); |
| 884 | |
| 885 | foreach ( array_keys($wp_meta_boxes[$this->id]) as $context ) { |
| 886 | foreach ( array_keys($wp_meta_boxes[$this->id][$context]) as $priority ) { |
| 887 | foreach ( $wp_meta_boxes[$this->id][$context][$priority] as $box ) { |
| 888 | if ( false == $box || ! $box['title'] ) |
| 889 | continue; |
| 890 | // Submit box cannot be hidden |
| 891 | if ( 'submitdiv' == $box['id'] || 'linksubmitdiv' == $box['id'] ) |
| 892 | continue; |
| 893 | $box_id = $box['id']; |
| 894 | $html = '<label class="ab-item" for="' . $box_id . '-hide">' . |
| 895 | '<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"' : '') . ' />' . |
| 896 | "{$box['title']}</label>\n"; |
| 897 | $wp_admin_bar->add_menu( array( |
| 898 | 'id' => 'show-on-screen-' . $box_id, |
| 899 | 'parent' => $parent, |
| 900 | 'href' => '', |
| 901 | 'meta' => array( 'html' => $html ), |
| 902 | ) ); |
916 | | foreach ( $columns as $column => $title ) { |
917 | | // Can't hide these for they are special |
918 | | if ( in_array( $column, $special ) ) |
919 | | continue; |
920 | | if ( empty( $title ) ) |
921 | | continue; |
922 | | |
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"; |
| 907 | if ( 'dashboard' === $this->id && current_user_can( 'edit_theme_options' ) ) { |
| 908 | if ( isset( $_GET['welcome'] ) ) { |
| 909 | $welcome_checked = empty( $_GET['welcome'] ) ? 0 : 1; |
| 910 | update_user_meta( get_current_user_id(), 'show_welcome_panel', $welcome_checked ); |
| 911 | } else { |
| 912 | $welcome_checked = get_user_meta( get_current_user_id(), 'show_welcome_panel', true ); |
| 913 | if ( 2 == $welcome_checked && wp_get_current_user()->user_email != get_option( 'admin_email' ) ) |
| 914 | $welcome_checked = false; |
930 | | ?> |
931 | | <br class="clear" /> |
932 | | </div> |
933 | | <?php endif; |
| 916 | $html = '<label class="ab-item" for="wp_welcome_panel-hide">' . |
| 917 | '<input type="checkbox" id="wp_welcome_panel-hide"' . checked( (bool) $welcome_checked, true, false ) . ' />' . |
| 918 | _x( 'Welcome', 'Welcome panel' ) . "</label>\n"; |
| 919 | $wp_admin_bar->add_menu( array( |
| 920 | 'id' => 'show-on-screen-' . $box_id, |
| 921 | 'parent' => $parent, |
| 922 | 'href' => '', |
| 923 | 'meta' => array( 'html' => $html ), |
| 924 | ) ); |
| 925 | } |
| 926 | } |
939 | | ?> |
940 | | <div><?php wp_nonce_field( 'screen-options-nonce', 'screenoptionnonce', false ); ?></div> |
941 | | </form> |
942 | | </div> |
943 | | <?php |
| 932 | if ( ! empty( $columns['_title'] ) ) { |
| 933 | echo '<h5>' . $columns['_title'] . '</h5>'; |
| 934 | } |
| 935 | |
| 936 | $special = array( '_title', 'cb', 'comment', 'media', 'name', 'title', 'username', 'blogname' ); |
| 937 | |
| 938 | foreach ( $columns as $column => $title ) { |
| 939 | // Can't hide these for they are special |
| 940 | if ( in_array( $column, $special ) ) |
| 941 | continue; |
| 942 | if ( empty( $title ) ) |
| 943 | continue; |
| 944 | |
| 945 | if ( 'comments' == $column ) |
| 946 | $title = __( 'Comments' ); |
| 947 | $id = "$column-hide"; |
| 948 | $html = '<label class="ab-item" for="' . $id . '">' . |
| 949 | '<input class="hide-column-tog" name="' . $id . '" type="checkbox" id="' . $id . '" value="' . $column . '"' . checked( !in_array($column, $hidden), true, false ) . ' />' . |
| 950 | "$title</label>\n"; |
| 951 | $wp_admin_bar->add_menu( array( |
| 952 | 'id' => 'show-on-screen-' . $column, |
| 953 | 'parent' => $parent, |
| 954 | 'href' => '', |
| 955 | 'meta' => array( 'html' => $html ), |
| 956 | ) ); |
| 957 | } |
| 958 | } |
946 | | /** |
947 | | * Render the option for number of columns on the page |
948 | | * |
949 | | * @since 3.3.0 |
950 | | */ |
951 | | function render_screen_layout() { |
| 961 | function render_layout( $parent, $wp_admin_bar ) { |
| 962 | // Back compat for plugins using the filter instead of add_screen_option() |
| 963 | $columns = apply_filters( 'screen_layout_columns', array(), $this->id, $this ); |
| 964 | |
| 965 | if ( ! empty( $columns ) && isset( $columns[ $this->id ] ) ) |
| 966 | $this->add_option( 'layout_columns', array('max' => $columns[ $this->id ] ) ); |
| 967 | |
| 968 | if ( $this->get_option( 'layout_columns' ) ) { |
| 969 | $this->columns = (int) get_user_option("screen_layout_$this->id"); |
| 970 | |
| 971 | if ( ! $this->columns && $this->get_option( 'layout_columns', 'default' ) ) |
| 972 | $this->columns = $this->get_option( 'layout_columns', 'default' ); |
| 973 | } |
| 974 | $GLOBALS[ 'screen_layout_columns' ] = $this->columns; // Set the global for back-compat. |
| 975 | |
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 |
| 982 | $wp_admin_bar->add_menu( array( |
| 983 | 'id' => 'column-layout', |
| 984 | 'parent' => $parent, |
| 985 | 'href' => '', |
| 986 | 'meta' => array( 'html' => '<h5 class="ab-item">' . __( 'Column Layout' ) . '</h5>' ), |
| 987 | ) ); |
| 988 | |
| 989 | for ( $i = 1; $i <= $num; ++$i ) { |
| 990 | $html = '<label class="ab-item" class="columns-prefs-' . $i . '">' . |
| 991 | "<input type='radio' name='screen_columns' value='" . $i . "'" . |
| 992 | checked( $screen_layout_columns, $i, false ) . '/>' . |
| 993 | esc_html( $i ) . |
| 994 | '</label>'; |
| 995 | |
| 996 | $wp_admin_bar->add_menu( array( |
| 997 | 'id' => 'column-layout-' . $i, |
| 998 | 'parent' => $parent, |
| 999 | 'href' => '', |
| 1000 | 'meta' => array( 'html' => $html ), |
| 1001 | ) ); |
| 1002 | } |
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; |
| 1043 | $wp_admin_bar->add_menu( array( |
| 1044 | 'id' => 'per-page', |
| 1045 | 'parent' => $parent, |
| 1046 | 'href' => '', |
| 1047 | 'meta' => array( 'html' => '<h5 class="ab-item">' . __( 'Items Per Page' ) . '</h5>' ), |
| 1048 | ) ); |
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 |
| 1050 | if ( $per_page_label ) { |
| 1051 | $html = '<input type="number" step="1" min="1" max="999" class="screen-per-page" name="wp_screen_options[value]" |
| 1052 | id="' . esc_attr( $option ) . '" maxlength="3" value="' . esc_attr( $per_page ) . '" />' . |
| 1053 | '<label class="ab-item" for="' . esc_attr( $option ) . '">' . |
| 1054 | esc_html( $per_page_label ) . |
| 1055 | '</label>'; |
| 1056 | $wp_admin_bar->add_menu( array( |
| 1057 | 'id' => 'per-page-1', |
| 1058 | 'parent' => $parent, |
| 1059 | 'href' => '', |
| 1060 | 'meta' => array( 'html' => $html ), |
| 1061 | ) ); |
| 1062 | } |
| 1063 | |
| 1064 | $html = get_submit_button( __( 'Apply' ), 'button', 'screen-options-apply', false ) . |
| 1065 | "<input type='hidden' name='wp_screen_options[option]' value='" . esc_attr($option) . "' />"; |
| 1066 | |
| 1067 | $wp_admin_bar->add_menu( array( |
| 1068 | 'id' => 'per-page-submit', |
| 1069 | 'parent' => $parent, |
| 1070 | 'href' => '', |
| 1071 | 'meta' => array( 'html' => $html ), |
| 1072 | ) ); |