options = $options; add_action( 'admin_init', [ $this, 'init' ] ); } /** * Option keys that only the Pro settings UI writes. * * @return string[] */ protected function get_pro_only_option_keys(): array { return [ 'post_types', 'edit_roles' ]; } /** * Start the engine running * * @return void */ public function init() { $this->settings_options = [ [ 'option_group' => Modified_Date::MENU_SLUG, 'option_name' => Modified_Date::OPTION_NAME, 'args' => [ 'sanitize_callback' => [ $this, 'sanitize_settings' ] ], ], ]; $this->settings_sections = [ [ 'id' => 'adminoptimizer-modified-date-default', 'title' => '', 'description' => '', 'menu_slug' => Modified_Date::MENU_SLUG, 'option_name' => Modified_Date::OPTION_NAME, 'fields' => [ [ 'type' => 'checkbox', 'title' => __( 'Lock modification date by default', 'admin-optimizer' ), 'id' => 'post-modified-date', 'name' => 'disable_modified_date_update', 'label' => __( 'Prevent any user from updating the modified post. Can be overridden for each post.', 'admin-optimizer' ), ], [ 'type' => 'checkbox', 'title' => __( 'Only lock modified date for Published post', 'admin-optimizer' ), 'id' => 'publish-post-modified-date', 'name' => 'publish_only', 'label' => __( 'The modification date of post with different post status will not be locked.', 'admin-optimizer' ), ], [ 'type' => 'checkbox', 'title' => __( 'Add a Modified Date column to Posts section', 'admin-optimizer' ), 'id' => 'post-modified-date-column', 'name' => 'add_modified_date_column', 'label' => __( 'Sort the post oder by Modified Date', 'admin-optimizer' ), ], ], ], ]; if ( $this->is_pro_active() ) { $this->settings_sections = $this->inject_pro_fields( $this->settings_sections, 'adminoptimizer-modified-date-default', [ [ 'type' => 'callback', 'title' => __( 'Lock modified date for the following Post Types', 'admin-optimizer' ), 'id' => 'post-types-support', 'name' => 'post_types', 'desc' => '', 'callback' => [ $this, 'render_post_types_fields' ], ], [ 'type' => 'callback', 'id' => 'modified-date-edit-roles', 'name' => 'edit_roles', 'title' => __( 'Only allow these user roles to make changes to the Modified Date', 'admin-optimizer' ), 'callback' => [ $this, 'render_edit_roles_checkboxes' ], 'desc' => __( 'Only these roles can lock or update the modified date.', 'admin-optimizer' ), ], ] ); } else { $this->settings_sections[] = [ 'id' => 'adminoptimizer-modified-date-pro', 'title' => __( 'Pro Options', 'admin-optimizer' ), /* translators: %1$s is the anchor link to the Pro version. %2$s is the closing anchor tag */ 'description' => sprintf( __( 'Upgrade to the %1$sPro version%2$s to access these features', 'admin-optimizer' ), '', '' ), 'menu_slug' => Modified_Date::MENU_SLUG . '_pro', 'option_name' => Modified_Date::OPTION_NAME, 'args' => [ 'before_section' => '
', ], 'fields' => [ [ 'type' => 'callback', 'title' => __( 'Lock modified date for the following Post Types', 'admin-optimizer' ), 'id' => 'post-types-support', 'name' => 'post_types', 'desc' => '', 'callback' => [ $this, 'render_disabled_post_types_fields' ], ], [ 'type' => 'callback', 'id' => 'modified-date-edit-roles', 'name' => 'edit_roles', 'title' => __( 'Only allow these user roles to make changes to the Modified Date', 'admin-optimizer' ), 'callback' => [ $this, 'render_disabled_edit_roles_checkboxes' ], 'desc' => __( 'Only these roles can lock or update the modified date.', 'admin-optimizer' ), ], ], ]; } $this->setup(); } /** * Callback function for rendering the Pro-enabled custom post types field. * * @return void */ public function render_post_types_fields() { $option = []; if ( ! isset( $this->options['post_types'] ) ) { $option['post_types'] = [ 'post' ]; } else { $option['post_types'] = $this->options['post_types']; } $custom_post_types = get_post_types( [ 'show_ui' => true, '_builtin' => false, 'public' => true, ], 'objects' ); $post_types = []; foreach ( $custom_post_types as $custom_post_type ) { $post_types[ $custom_post_type->name ] = $custom_post_type->label; } $post_types = array_merge( [ 'all' => __( 'All Post Types', 'admin-optimizer' ), 'post' => 'Post', 'page' => 'Page', ], $post_types ); foreach ( $post_types as $post_type_name => $post_type_label ) : ?>' . esc_html( $field['desc'] ) . '