textdomain = 'admin-customization'; $this->args = array( 'page_title' => __( 'Admin Customization Settings', $this->textdomain ), 'menu_title' => __( 'Admin Customization' , $this->textdomain ), 'page_slug' => 'admin-customization', ); $this->boxes = array( array( 'style_preferences', __( 'Style preferences', $this->textdomain ), 'normal' ), array( 'dashboard_settings', __( 'Dashboard widgets', $this->textdomain ), 'side' ), array( 'general_settings', __( 'General settings', $this->textdomain ), 'normal' ), ); } /** * Helper method that verifies if a file exists * * @param $file - path to file relative to wp-content * @param $echo_error - if true, echoes a wordpress error if the file is * missing * * @returns true - if file exists, false - if it does not, nothing if file * path is empty */ private function verify_file_existence( $file, $echo_error=false ) { // If favicon file does not exist, alert the user if ( !empty( $file ) ) { if ( !file_exists( ABSPATH . 'wp-content/' . $file ) ) { if ( $echo_error ) { $file_url = site_url( 'wp-content/' . $file ); ?>

Cannot find any file at

\n"; screen_icon(); echo "

" . $this->args['page_title'] . "

\n"; echo '

' . __( 'Note: If you don\'t see any changes immediately after you saved, just refresh or visit a different admin page.', $this->textdomain ) . "

"; $this->verify_file_existence( $this->options->favicon, true ); $this->verify_file_existence( $this->options->login_logo, true ); $this->verify_file_existence( $this->options->admin_logo, true ); } function general_settings_box() { $output = ''; $checkboxes = array( __( 'Hide update notices', $this->textdomain ) => array( 'value' => 'hide_update_notices', ), __( 'Hide plugin update count', $this->textdomain ) => array( 'value' => 'hide_plugin_count', ), __( 'Redirect to home page on logout', $this->textdomain ) => array( 'value' => 'redirect_on_logout', ), ); foreach ( $checkboxes as $name => $args ) { $output .= html( 'tr', html( 'td', $this->input( array( 'type' => 'checkbox', 'name' => 'general[]', 'value' => $args['value'], 'desc' => $name, 'checked' => in_array( $args['value'], (array) $this->options->general_settings ), ) ) ) ); } echo $this->form_wrap( html( 'table class="checklist widefat notitle"', $output ), array('action' => 'general_preferences_button')); } function general_settings_handler() { if ( !isset( $_POST['general_preferences_button'] ) ) return; $this->admin_msg( __( 'General settings saved. Please refresh to see the changes.', $this->textdomain ) ); $this->options->general_settings = (array) @$_POST['general']; // Refresh page // header( 'Location: ' . admin_url('options-general.php?page=admin-customization') ); } function style_preferences_box() { $favicon_exists = $this->verify_file_existence($this->options->favicon); $login_logo_exists = $this->verify_file_existence($this->options->login_logo); $admin_logo_exists = $this->verify_file_existence($this->options->admin_logo); $output = $this->table( array( array( 'title' => __( 'Favicon', $this->textdomain ), 'desc' => __( '(favicon path realative to wp-content)', $this->textdomain ), 'type' => 'text', 'name' => 'favicon', 'extra' => empty( $favicon_exists ) ? array( 'class' => 'regular-text' ) : array( 'class' => 'ac_found regular-text' ), 'value' => implode( ', ', (array) $this->options->favicon ) ), array( 'title' => __( 'Login logo', $this->textdomain ), 'desc' => __( '(login logo path relative to wp-content)', $this->textdomain ), 'type' => 'text', 'name' => 'login_logo', 'extra' => empty( $login_logo_exists ) ? array( 'class' => 'regular-text' ) : array( 'class' => 'ac_found regular-text' ), 'value' => implode( ', ', (array) $this->options->login_logo ) ), array( 'title' => __( 'Admin logo ', $this->textdomain ), 'desc' => __( '(admin logo path relative to wp-content.)
e.g.: "themes/mytheme/img/admin_logo.png"', $this->textdomain ), 'type' => 'text', 'name' => 'admin_logo', 'extra' => empty( $admin_logo_exists ) ? array( 'class' => 'regular-text' ) : array( 'class' => 'ac_found regular-text' ), 'value' => implode( ', ', (array) $this->options->admin_logo ) ), array( 'title' => false, 'type' => 'checkbox', 'name' => 'style_settings[]', 'value' => 'hide_logo', 'desc' => __( 'Hide admin logo', $this->textdomain ), 'checked' => in_array( 'hide_logo', (array) $this->options->style_settings ) ), array( 'title' => __( 'Logo text font size', $this->textdomain ), 'desc' => __( 'The font size in pixels. Non-numeric characters will be stripped.', $this->textdomain ), 'type' => 'text', 'name' => 'admin_logo_font_size', 'value' => implode( ', ', (array) $this->options->admin_logo_font_size ) ), array( 'title' => false, 'type' => 'checkbox', 'name' => 'style_settings[]', 'value' => 'hide_logo_name', 'desc' => __( 'Hide admin logo text', $this->textdomain ), 'checked' => in_array( 'hide_logo_name', (array) $this->options->style_settings ) ), array( 'title' => __( 'Admin footer text left', $this->textdomain ), 'desc' => __( 'Replacement for the left footer text. Accepts HTML.', $this->textdomain ), 'type' => 'text', 'name' => 'admin_footer_left', 'value' => implode( ', ', (array)$this->options->admin_footer_left ) ), array( 'title' => __( 'Admin footer text right', $this->textdomain ), 'desc' => __( 'Replacement for the Wordpress version footer text on the right. Accepts HTML.', $this->textdomain ), 'type' => 'text', 'name' => 'admin_footer_right', 'value' => implode( ', ', (array) $this->options->admin_footer_right ) ), ) ); // same as $this->form_wrap( $output, '', 'style_preferences_button'); echo $this->form_wrap( $output, array('action' => 'style_preferences_button')); } function style_preferences_handler() { if ( !isset( $_POST['style_preferences_button'] ) ) return; $this->admin_msg( __( 'Style preferences changes saved. Please refresh to see the changes.', $this->textdomain ) ); foreach ( array( 'favicon', 'login_logo', 'admin_logo', 'style_settings' ) as $key ) { $this->options->$key = @$_POST[$key]; } foreach ( array( 'admin_footer_left', 'admin_footer_right' ) as $key ) { $this->options->$key = htmlspecialchars ( stripslashes( @$_POST[$key] ) ); } // Strip non-numeric characters from the font size $font_size = ereg_replace( "[^0-9]", "", @$_POST['admin_logo_font_size'] ); $this->options->admin_logo_font_size = empty( $font_size ) ? 16 : $font_size; // Refresh page // header( 'Location: ' . admin_url('options-general.php?page=admin-customization') ); } function dashboard_settings_box() { $output = '

' . __( 'To update this list of widgets you must first visit the Dashboard.', $this->textdomain ) . '

' . $this->_widget_table(__( 'Disable All Widgets', $this->textdomain ), $this->options->widgets); // same as $this->form_wrap( $output, '', 'dashboard_settings_button'); echo $this->form_wrap( $output, array('action' => 'dashboard_settings_button')); } function dashboard_settings_handler() { if ( !isset ( $_POST['dashboard_settings_button'] ) ) return; $this->admin_msg( __( 'Dashboard widgets settings saved.', $this->textdomain ) ); $this->options->disabled_widgets = (array) @$_POST['widgets']; } function default_css() { ?> ' ) .html( 'th scope="col"', '' ) ); $table = html( 'table class="checklist widefat"', html( 'thead', $thead ) .html( 'tbody', $tbody ) ); return $table; } private function _widget_table( $title, $widgets ) { $tbody = ''; foreach ( $widgets as $widget ) { if ( empty( $widget['title'] ) ) continue; $tbody .= html( 'tr', html( 'th scope="row" class="check-column"', $this->input( array( 'type' => 'checkbox', 'name' => 'widgets[]', 'value' => $widget['id'], 'desc' => false, 'extra' => array( 'id' => $widget['id'] ), 'checked' => in_array( $widget['id'], (array) $this->options->disabled_widgets ), ) ) ) .html( 'td', '') ); } return $this->_checklist_wrap( $title, $tbody ); } }