├── admin
└── class-settings.php
├── changelog.md
├── contributing.md
├── inc
├── functions-deprecated.php
├── functions-filters.php
├── functions-options.php
├── functions-rewrite.php
├── functions-shortcodes.php
├── functions-taxonomies.php
├── template-general.php
└── widgets
│ ├── class-list-posts.php
│ └── class-list-related.php
├── lang
└── series.pot
├── license.md
├── readme.md
├── readme.txt
├── screenshot-1.png
├── screenshot-2.png
├── screenshot-3.png
├── screenshot-4.png
└── series.php
/admin/class-settings.php:
--------------------------------------------------------------------------------
1 |
7 | * @copyright Copyright (c) 2009 - 2018, Justin Tadlock
8 | * @link https://themehybrid.com/plugins/series
9 | * @license http://www.gnu.org/licenses/old-licenses/gpl-2.0.html
10 | */
11 |
12 | namespace Series;
13 |
14 | /**
15 | * Sets up and handles the plugin settings screen.
16 | *
17 | * @since 2.0.0
18 | * @access public
19 | */
20 | final class Settings_Page {
21 |
22 | /**
23 | * Settings page name.
24 | *
25 | * @since 2.0.0
26 | * @access public
27 | * @var string
28 | */
29 | public $settings_page = '';
30 |
31 | /**
32 | * Sets up the needed actions for adding and saving the meta boxes.
33 | *
34 | * @since 2.0.0
35 | * @access public
36 | * @return void
37 | */
38 | private function __construct() {
39 | add_action( 'admin_menu', array( $this, 'admin_menu' ) );
40 | }
41 |
42 | /**
43 | * Sets up custom admin menus.
44 | *
45 | * @since 2.0.0
46 | * @access public
47 | * @return void
48 | */
49 | public function admin_menu() {
50 |
51 | // Create the settings page.
52 | $this->settings_page = add_options_page(
53 | esc_html__( 'Series Settings', 'series' ),
54 | esc_html__( 'Series', 'series' ),
55 | apply_filters( 'series/settings_capability', 'manage_options' ),
56 | 'series-settings',
57 | array( $this, 'settings_page' )
58 | );
59 |
60 | if ( $this->settings_page ) {
61 |
62 | // Register settings.
63 | add_action( 'admin_init', array( $this, 'register_settings' ) );
64 | }
65 | }
66 |
67 | /**
68 | * Registers the plugin settings.
69 | *
70 | * @since 2.0.0
71 | * @access public
72 | * @return void
73 | */
74 | function register_settings() {
75 |
76 | // Register the setting.
77 | register_setting( 'series_settings', 'series_settings', array( $this, 'validate_settings' ) );
78 |
79 | /* === Settings Sections === */
80 |
81 | add_settings_section( 'reading', esc_html__( 'Reading', 'series' ), array( $this, 'section_reading' ), $this->settings_page );
82 | add_settings_section( 'permalinks', esc_html__( 'Permalinks', 'series' ), array( $this, 'section_permalinks' ), $this->settings_page );
83 |
84 | /* === Settings Fields === */
85 |
86 | // Reading section fields.
87 | add_settings_field( 'posts_per_page', esc_html__( 'Posts Per Page', 'series' ), array( $this, 'field_posts_per_page' ), $this->settings_page, 'reading' );
88 | add_settings_field( 'posts_orderby', esc_html__( 'Sort By', 'series' ), array( $this, 'field_posts_orderby' ), $this->settings_page, 'reading' );
89 | add_settings_field( 'posts_order', esc_html__( 'Order', 'series' ), array( $this, 'field_posts_order' ), $this->settings_page, 'reading' );
90 |
91 | // Permalinks section fields.
92 | add_settings_field( 'series_rewrite_base', esc_html__( 'Series Slug', 'series' ), array( $this, 'field_series_rewrite_base' ), $this->settings_page, 'permalinks' );
93 | }
94 |
95 | /**
96 | * Validates the plugin settings.
97 | *
98 | * @since 2.0.0
99 | * @access public
100 | * @param array $input
101 | * @return array
102 | */
103 | function validate_settings( $settings ) {
104 |
105 | // Text boxes.
106 | $settings['series_rewrite_base'] = $settings['series_rewrite_base'] ? trim( strip_tags( $settings['series_rewrite_base'] ), '/' ) : '';
107 |
108 | // Numbers.
109 | $posts_per_page = intval( $settings['posts_per_page'] );
110 | $settings['posts_per_page'] = -2 < $posts_per_page ? $posts_per_page : 10;
111 |
112 | // Select boxes.
113 | $settings['posts_orderby'] = isset( $settings['posts_orderby'] ) ? strip_tags( $settings['posts_orderby'] ) : 'date';
114 | $settings['posts_order'] = isset( $settings['posts_order'] ) ? strip_tags( $settings['posts_order'] ) : 'DESC';
115 |
116 | /* === Handle Permalink Conflicts ===*/
117 |
118 | // Return the validated/sanitized settings.
119 | return $settings;
120 | }
121 |
122 | /**
123 | * Reading section callback.
124 | *
125 | * @since 2.0.0
126 | * @access public
127 | * @return void
128 | */
129 | public function section_reading() { ?>
130 |
131 |
132 |
133 |
134 |
144 |
145 |
148 | __( 'Author', 'series' ),
161 | 'date' => __( 'Date (Published)', 'series' ),
162 | 'modified' => __( 'Date (Modified)', 'series' ),
163 | 'ID' => __( 'ID', 'series' ),
164 | 'rand' => __( 'Random', 'series' ),
165 | 'name' => __( 'Slug', 'series' ),
166 | 'title' => __( 'Title', 'series' )
167 | ); ?>
168 |
169 |