page, $this->setting, array( &$this, 'clean_setting' ) ); add_settings_section( $this->section, __( 'Archive Disabler Options', 'cd-archive-disabler' ), array( &$this, 'section_cb' ), 'reading' ); $this->add_field( 'date', __( 'Date Archives', 'cd-archive-disabler' ) ); $this->add_field( 'author', __( 'Author Archives', 'cd-archive-disabler' ) ); $this->add_field( 'taxonomies', __( 'Taxonomy Archives', 'cd-archive-disabler' ) ); if( $this->types() ) { $this->add_field( 'post_types', __( 'Post Type Archives', 'cd-archive-disabler' ) ); } $this->add_field( 'on_catch', __( 'Disabled archives should...', 'cd-archive-disabler' ) ); } /** * Callback function for our section * * @since 1.0 */ function section_cb() { ?>
checkbox( 'date', $args, __( 'Disable Date Archives', 'cd-archive-disabler' ) ); } /** * Callback for author archive option * * @since 1.0 */ function author_field_cb( $args ) { echo $this->checkbox( 'author', $args, __( 'Disable Author Archives', 'cd-archive-disabler' ) ); } /** * Callback for taxonomy archives option * * @since 1.0 */ function taxonomies_field_cb() { echo $this->list_display( $this->taxonomies() ); } /** * Callback for post type archives options * * @since 1.0 */ function post_types_field_cb() { echo $this->list_display( $this->types() ); } /** * Callback for on_catch option * * @since 1.0 */ function on_catch_field_cb( $args ) { $actions = array( 'redirect' => __( 'Redirect to the home page', 'cd-archive-disabler' ), 'error' => __( 'Throw a 404 Not Found Error', 'cd-archive-disabler' ) ); foreach( $actions as $action => $label ): ?>
'; esc_html_e( 'Archive Disabler allows you to "disable" the various WordPress archive pages. ' . 'To do so, check the archives you wish to have disabled below.', 'cd-archive-disabler' ); echo '
'; esc_html_e( 'Depending on your options, the disabled archives will redirect to the home page or simply 404. ' . 'Redirecting archives, especially if they were previously enabled, is recommended.', 'cd-archive-disabler' ); echo '
'; printf( __( 'Learn more about the author of Archive Disabler, %s. Problems? Report bugs here: %s', 'cd-archive-disabler' ), 'Christopher Davis', 'https://github.com/chrisguitarguy/Archive-Disabler/issues' ); echo '
'; } /** * Plugin action links filter. Adds a "settings" link to the plugin * actions * * @since 1.0 */ function actions( $actions ) { $link = admin_url( 'options-reading.php#archive-disabler' ); $actions['settings'] = sprintf( '%s', esc_url( $link ), esc_html__( 'Settings', 'cd-archive-disabler' ) ); return $actions; } /** * Utility method to fetch all public post types that have archives * * @since 1.0 * @access protected * @uses get_post_types To fetch the post types we want * @return array The post type as the key and the label as the value */ protected function types() { $types = get_post_types( array( 'public' => true, 'has_archive' => true ), 'object' ); $rv = array(); if( ! empty( $types ) ) { foreach( $types as $t => $obj ) { $rv['posttype_' . $t] = isset( $obj->labels->singular_name ) ? $obj->labels->singular_name : $obj->label; } } return $rv; } /** * Utility method to fetch our taxonomies. * * @since 1.0 * @access protected * @uses get_taxonomies To fetch a list of all taxonomies * @return array With taxonomy slugs as the keys and a label as the value */ protected function taxonomies() { $taxes = get_taxonomies( array( 'public' => true ), 'objects' ); $rv = array(); if( ! empty( $taxes ) ) { foreach( $taxes as $t => $obj ) { $rv['taxonomy_' . $t] = isset( $obj->labels->singular_name ) ? $obj->labels->singular_name : $obj->label; } } return $rv; } /** * Wrapper callback to echo out lists of options * * @since 1.0 * @access protected * @return string A list of checkboxes */ protected function list_display( $items ) { $opts = get_option( $this->setting, array() ); $rv = ''; foreach( $items as $t => $label ) { $rv .= $this->checkbox( $t, isset( $opts[$t] ) ? $opts[$t] : 'off', sprintf( __( 'Disable %s Archives', 'cd-archive-disabler' ), esc_html( $label ) ) ); $rv .= '