PluginProbe
QuadMenu – Mega Menu / trunk
QuadMenu – Mega Menu vtrunk
3.3.7 3.3.6 trunk 1.8.4 1.8.5 1.8.7 1.8.8 1.8.9 1.9.0 1.9.2 1.9.3 1.9.4 1.9.5 1.9.6 1.9.7 1.9.8 1.9.9 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.0.5 2.0.6 2.0.7 All 87 releases
quadmenu / lib / class-themes.php

class-themes.php in QuadMenu – Mega Menu trunk, at lib/class-themes.php

206 lines 5.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 namespace QuadLayers\QuadMenu;
4
5 use QuadLayers\QuadMenu\Compiler;
6 use QuadLayers\QuadMenu\Redux_Legacy;
7
8 if ( ! defined( 'ABSPATH' ) ) {
9 die( '-1' );
10 }
11
12 /**
13 * Themes Class ex QuadMenu_Themes
14 */
15 class Themes {
16
17 private static $instance;
18
19 public function __construct() {
20
21 $this->themes();
22
23 add_filter( 'quadmenu_developer_options', array( $this, 'options' ) );
24
25 add_action( 'wp_ajax_quadmenu_add_theme', array( $this, 'ajax_theme_create' ) );
26
27 add_action( 'wp_ajax_quadmenu_delete_theme', array( $this, 'ajax_theme_delete' ) );
28
29 add_action( 'redux/options/' . QUADMENU_DB_OPTIONS . '/import', array( $this, 'import' ), 10, 2 );
30
31 add_action( 'redux/options/' . QUADMENU_DB_OPTIONS . '/settings/change', array( $this, 'title' ), 10, 2 );
32
33 add_action( 'wp_ajax_' . QUADMENU_DB_OPTIONS . '_ajax_save', array( $this, 'themes_delete' ) );
34 }
35
36 public function themes() {
37
38 global $quadmenu_themes;
39
40 $defaults = array(
41 'default_theme' => esc_html( 'Default Theme', 'quadmenu' ),
42 );
43
44 $custom = (array) get_option( QUADMENU_DB_THEMES, array() );
45
46 $quadmenu_themes = apply_filters( 'quadmenu_default_themes', wp_parse_args( $custom, $defaults ) );
47 }
48
49 public function options( $options ) {
50
51 global $quadmenu_themes;
52
53 if ( $saved_themes = get_option( QUADMENU_DB_THEMES, array() ) ) {
54 $options['quadmenu_themes'] = $saved_themes;
55 }
56
57 $options['themes'] = $this->less_themes( $quadmenu_themes );
58
59 return $options;
60 }
61
62 static function less_themes( $quadmenu_themes ) {
63
64 $themes = array();
65
66 if ( is_array( $quadmenu_themes ) && count( $quadmenu_themes ) ) {
67
68 foreach ( $quadmenu_themes as $key => $theme ) {
69
70 $themes[] = '~"' . $key . '"';
71 }
72
73 return implode( ',', array_reverse( $themes ) );
74 }
75
76 return '~"' . $quadmenu_themes . '"';
77 }
78
79 public function import( $plugin_options = null, $imported_options = null ) {
80
81 if ( ! empty( $imported_options['quadmenu_themes'] ) ) {
82 update_option( QUADMENU_DB_THEMES, $imported_options['quadmenu_themes'] );
83 }
84 }
85
86 public function ajax_theme_create() {
87
88 if ( ! check_ajax_referer( 'quadmenu', 'nonce', false ) ) {
89 Plugin::send_json_error( esc_html__( 'Please reload the page.', 'quadmenu' ) );
90 }
91
92 do_action( 'quadmenu_delete_theme' );
93
94 $saved_themes = get_option( QUADMENU_DB_THEMES, array() );
95
96 $next_id = count( $saved_themes ) + 1;
97
98 $next_key = 'custom_theme_' . $next_id;
99
100 $saved_themes[ $next_key ] = sprintf( esc_html__( 'Custom Theme %s', 'quadmenu' ), $next_id );
101
102 if ( update_option( QUADMENU_DB_THEMES, $saved_themes ) ) {
103
104 Compiler::do_compiler( true );
105
106 Redux_Legacy::add_notification( 'blue', sprintf( esc_html__( 'New theme created. Your options panel will be reloaded to include their options. %s.', 'quadmenu' ), esc_html__( 'Please wait', 'quadmenu' ) ) );
107
108 Plugin::send_json_success( Plugin::taburl( 'quadmenu_theme_' . $next_key ) );
109 } else {
110 Plugin::send_json_error( esc_html__( 'Can\'t create theme.', 'quadmenu' ) );
111 }
112
113 wp_die();
114 }
115
116 public function ajax_theme_delete() {
117
118 if ( ! check_ajax_referer( 'quadmenu', 'nonce', false ) ) {
119 Plugin::send_json_error( esc_html__( 'Please reload the page.', 'quadmenu' ) );
120 }
121
122 do_action( 'quadmenu_delete_theme' );
123
124 global $quadmenu_themes;
125
126 if ( ! empty( $_REQUEST['current_theme'] ) ) {
127
128 $key = sanitize_text_field( $_REQUEST['current_theme'] );
129
130 $saved_themes = get_option( QUADMENU_DB_THEMES, array() );
131
132 unset( $saved_themes[ $key ] );
133
134 $prev_key = reset( array_keys( $quadmenu_themes ) );
135
136 if ( update_option( QUADMENU_DB_THEMES, $saved_themes ) ) {
137
138 Compiler::do_compiler( true );
139
140 Redux_Legacy::add_notification( 'blue', sprintf( esc_html__( 'Theme deleted. Your options panel will be reloaded to remove their options. %s.', 'quadmenu' ), esc_html__( 'Please wait', 'quadmenu' ) ) );
141
142 Plugin::send_json_success( Plugin::taburl( 'quadmenu_theme_' . $prev_key ) );
143 } else {
144 Plugin::send_json_error( esc_html__( 'Can\'t delete theme.', 'quadmenu' ) );
145 }
146 }
147
148 wp_die();
149 }
150
151 function themes_delete() {
152
153 if ( ! empty( $_REQUEST['data'] ) && wp_verify_nonce( $_REQUEST['nonce'], 'redux_ajax_nonce' . QUADMENU_DB_OPTIONS ) ) {
154
155 $redux = \ReduxFrameworkInstancesLegacy::get_instance( QUADMENU_DB_OPTIONS );
156
157 $values = array();
158
159 $_REQUEST['data'] = stripslashes( $_REQUEST['data'] );
160
161 $values = $redux->redux_parse_str( $_REQUEST['data'] );
162 // $values = Redux_Functions_Ex::parse_str( $_REQUEST['data'] );
163
164 $values = $values[ QUADMENU_DB_OPTIONS ];
165
166 // if (function_exists('get_magic_quotes_gpc') && get_magic_quotes_gpc()) {
167 $values = array_map( 'stripslashes_deep', $values );
168 // }
169
170 if ( ! empty( $values['defaults'] ) ) {
171
172 delete_option( QUADMENU_DB_THEMES );
173 }
174 }
175 }
176
177 function title( $options = false, $changed = false ) {
178
179 $update = false;
180
181 if ( $saved_themes = get_option( QUADMENU_DB_THEMES, array() ) ) {
182
183 foreach ( $saved_themes as $key => $name ) {
184
185 if ( ! empty( $options[ $key . '_theme_title' ] ) && $options[ $key . '_theme_title' ] != $name ) {
186
187 $update = true;
188
189 $saved_themes[ $key ] = $options[ $key . '_theme_title' ];
190 }
191 }
192
193 if ( $update && update_option( QUADMENU_DB_THEMES, $saved_themes ) ) {
194 Redux_Legacy::add_notification( 'blue', esc_html__( 'Theme name changed.', 'quadmenu' ) );
195 }
196 }
197 }
198
199 public static function instance() {
200 if ( ! isset( self::$instance ) ) {
201 self::$instance = new self();
202 }
203 return self::$instance;
204 }
205 }
206