PluginProbe
Powered Cache – Caching and Optimization for WordPress – Easily Improve PageSpeed & Web Vitals Score / 1.2.2
Powered Cache – Caching and Optimization for WordPress – Easily Improve PageSpeed & Web Vitals Score v1.2.2
trunk 1.0 1.0.1 1.1 1.1.1 1.1.2 1.2 1.2.1 1.2.2 1.2.3 1.2.4 1.2.5 1.2.6 1.2.7 1.2.8 2.0 2.0.1 2.0.2 2.0.3 2.0.4 2.1 2.1.1 2.1.2 2.2 2.2.1 All 69 releases
powered-cache / includes / admin / class-powered-cache-extension-admin-base.php

class-powered-cache-extension-admin-base.php in Powered Cache – Caching and Optimization for WordPress – Easily Improve PageSpeed & Web Vitals Score 1.2.2, at includes/admin/class-powered-cache-extension-admin-base.php

120 lines 3.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 if ( ! defined( 'ABSPATH' ) ) {
3 exit;
4 }
5
6 class Powered_Cache_Extension_Admin_Base {
7
8 public $extension_id;
9 public $extension_name;
10 public $is_premium;
11 public $options;
12 public $capability = 'manage_options';
13 protected $fields;
14
15
16 protected function __construct( $args ) {
17 foreach ( $args as $key => $value ) {
18 $this->$key = $value;
19 }
20
21 $this->options = powered_cache_get_extension_settings( $this->extension_id );
22 $this->is_premium = powered_cache_is_premium();
23 }
24
25 /**
26 * Get things started
27 *
28 * @since 1.0
29 */
30 protected function setup() {
31 $this->capability = apply_filters( 'powered_cache_cap', $this->capability, $this->extension_id );
32
33 add_action( 'admin_menu', array( $this, 'admin_menu' ), 999 );
34 if ( property_exists( $this, 'admin_bar_menu' ) ) {
35 add_action( 'admin_bar_menu', array( $this, 'admin_bar_menu' ), 999 );
36 }
37 add_action( 'load-powered-cache_page_powered-cache-extension-' . $this->extension_id, array( $this, 'update_options' ) );
38 }
39
40 /**
41 * Adds menu item
42 *
43 * @since 1.0
44 */
45 public function admin_menu() {
46 global $powered_cache_plugin_pages;
47 $powered_cache_plugin_pages[ $this->extension_id ] = add_submenu_page( 'powered-cache', $this->extension_name, $this->extension_name, $this->capability,'powered-cache-extension-'. $this->extension_id, array( $this, 'settings_page' ) );
48 }
49
50 public function admin_bar_menu( $wp_admin_bar ) {
51 if ( current_user_can( $this->capability ) ) {
52 $wp_admin_bar->add_menu( array(
53 'id' => $this->extension_id,
54 'title' => $this->extension_name,
55 'href' => admin_url( 'admin.php?page=powered-cache-extension-' . $this->extension_id ),
56 'parent' => 'powered-cache',
57 ) );
58 }
59 }
60
61 public function settings_template( $settings_files = array() ) {
62 $this->settings_files = $settings_files;
63 require_once POWERED_CACHE_ADMIN_DIR . 'extension-settings.php';
64 }
65
66 public function get_option( $key ) {
67 if ( isset( $this->options[ $key ] ) ) {
68 return $this->options[ $key ];
69 } elseif ( isset( $this->fields[ $key ] ) && false !== $this->fields[ $key ]['default'] ) {
70 return $this->fields[ $key ]['default'];
71 }
72
73 return '';
74 }
75
76
77 public function is_premium() {
78 return $this->is_premium;
79 }
80
81
82 public function settings_page() {
83
84 }
85
86
87 public function update_options() {
88
89 Powered_Cache_Admin_Helper::check_cap_and_nonce( $this->capability );
90
91 if ( isset( $_REQUEST['extension'] ) && ( $_REQUEST['extension'] === $this->extension_id ) ) {
92 $_post = $_POST[ $this->extension_id ];
93
94
95 foreach ( $this->fields as $key => $field ) {
96 $options[ $key ] = $field['default'];
97
98 if ( isset( $_post[ $key ] ) ) {
99 $options[ $key ] = call_user_func( $field['sanitizer'], $_post[ $key ] );
100 } elseif ( 'boolval' === $field['sanitizer'] && ! isset( $_post[ $key ] ) ) {
101 //checkbox deleted option
102 $options[ $key ] = false;
103 }
104
105 }
106
107
108 if ( isset( $options ) && ( powered_cache_update_extension_option( $this->extension_id, $options ) ) ) {
109 // update runtime values
110 $this->options = $options;
111 }
112
113 $msg = __( 'Options updated', 'powered-cache' );
114 Powered_Cache_Admin_Helper::set_flash_message( $msg );
115 Powered_Cache_Admin_Actions::exit_with_redirect();
116 }
117 }
118
119
120 }