PluginProbe ʕ •ᴥ•ʔ
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents / 3.0.0
EmbedPress – PDF Embedder, 3D PDF FlipBook, Google Reviews, YouTube Videos, Upload & Embed PDF documents v3.0.0
4.6.0 4.5.6 4.5.5 4.5.4 4.5.3 4.5.2 trunk 1.0.0 1.1.0 1.1.1 1.1.2 1.1.3 1.2.0 1.3.0 1.3.1 1.4.0 1.4.1 1.4.2 1.4.3 1.4.4 1.5.0 1.6.0 1.6.1 1.6.2 1.6.3 1.7.0 1.7.1 1.7.2 1.7.3 1.7.4 1.7.5 2.0.0 2.0.1 2.0.2 2.0.3 2.1.0 2.1.1 2.1.2 2.1.3 2.1.4 2.1.5 2.1.6 2.2.0 2.2.1 2.2.2 2.3.0 2.3.1 2.3.2 2.3.3 2.4.0 2.4.1 2.5.0 2.5.1 2.5.2 2.5.3 2.5.4 2.5.5 2.6.0 2.6.1 2.6.2 2.7.0 2.7.1 2.7.2 2.7.3 2.7.4 2.7.5 2.7.6 2.7.7 3.0.0 3.0.1 3.0.2 3.0.3 3.0.4 3.1.0 3.1.1 3.1.2 3.1.3 3.2.0 3.2.1 3.3.0 3.3.1 3.3.2 3.3.3 3.3.4 3.3.5 3.3.6 3.3.7 3.4.0 3.4.1 3.4.2 3.4.3 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 3.6.2 3.6.3 3.6.4 3.6.5 3.6.6 3.6.7 3.6.8 3.7.0 3.7.1 3.7.2 3.7.3 3.8.0 3.8.1 3.8.2 3.8.3 3.8.4 3.8.5 3.9.0 3.9.1 3.9.10 3.9.11 3.9.12 3.9.13 3.9.14 3.9.15 3.9.16 3.9.17 3.9.2 3.9.3 3.9.4 3.9.5 3.9.6 3.9.7 3.9.8 3.9.9 4.0.0 4.0.1 4.0.10 4.0.11 4.0.12 4.0.13 4.0.14 4.0.2 4.0.3 4.0.4 4.0.5 4.0.6 4.0.7 4.0.8 4.0.9 4.1.0 4.1.1 4.1.10 4.1.2 4.1.3 4.1.4 4.1.5 4.1.6 4.1.7 4.1.8 4.1.9 4.2.0 4.2.1 4.2.2 4.2.3 4.2.4 4.2.5 4.2.6 4.2.7 4.2.8 4.2.9 4.3.0 4.3.1 4.4.0 4.4.1 4.4.10 4.4.11 4.4.2 4.4.3 4.4.4 4.4.5 4.4.6 4.4.7 4.4.8 4.4.9 4.5.0 4.5.1
embedpress / EmbedPress / Ends / Back / Settings / EmbedpressSettings.php
embedpress / EmbedPress / Ends / Back / Settings Last commit date
assets 5 years ago templates 5 years ago EmbedpressSettings.php 5 years ago
EmbedpressSettings.php
256 lines
1 <?php
2 namespace EmbedPress\Ends\Back\Settings;
3
4 class EmbedpressSettings {
5 var $page_slug = '';
6 /**
7 * @var int|string
8 */
9 protected $file_version;
10
11 public function __construct($page_slug = 'embedpress') {
12 $this->page_slug = $page_slug;
13 $this->file_version = defined( 'WP_DEBUG') && WP_DEBUG ? time() : EMBEDPRESS_VERSION;
14 add_action('admin_enqueue_scripts', [$this, 'handle_scripts_and_styles']);
15 add_action('admin_menu', [$this, 'register_menu']);
16 add_action( 'init', [$this, 'save_settings']);
17
18 // ajax
19 add_action( 'wp_ajax_embedpress_elements_action', [$this, 'update_elements_list']);
20
21 // Migration
22 $option = 'embedpress_elements_updated'; // to update initially for backward compatibility
23 if ( !get_option( $option, false) ) {
24 $elements_initial_states = [
25 'gutenberg' => [
26 'google-docs-block' => 'google-docs-block',
27 'document' => 'document',
28 'embedpress' => 'embedpress',
29 'google-sheets-block' => 'google-sheets-block',
30 'google-slides-block' => 'google-slides-block',
31 'youtube-block' => 'youtube-block',
32 'google-forms-block' => 'google-forms-block',
33 'google-drawings-block' => 'google-drawings-block',
34 'google-maps-block' => 'google-maps-block',
35 'twitch-block' => 'twitch-block',
36 'wistia-block' => 'wistia-block',
37 'vimeo-block' => 'vimeo-block',
38 ],
39 'elementor' => [
40 'embedpress-document' => 'embedpress-document',
41 'embedpress' => 'embedpress',
42 ]
43 ];
44
45 $settings = get_option( EMBEDPRESS_PLG_NAME, [] );
46 $yt = get_option( EMBEDPRESS_PLG_NAME.':youtube' );
47 if ( empty( $settings) && empty( $yt) ) {
48 $settings['need_first_time_redirect'] = true;
49 }
50 if ( !isset( $settings['enablePluginInAdmin']) ) {
51 $settings['enablePluginInAdmin'] = 1;
52 }
53 if ( !isset( $settings['enablePluginInFront']) ) {
54 $settings['enablePluginInFront'] = 1;
55 }
56
57 update_option( EMBEDPRESS_PLG_NAME.":elements", $elements_initial_states);
58 update_option( EMBEDPRESS_PLG_NAME, $settings);
59 update_option( $option, true);
60 }
61 add_action( 'admin_init', [$this, 'embedpress_maybe_redirect_to_settings'] );
62
63
64 }
65 function embedpress_maybe_redirect_to_settings() {
66 $settings = get_option( EMBEDPRESS_PLG_NAME, [] );
67 if ( isset( $settings['need_first_time_redirect']) && $settings['need_first_time_redirect'] ) {
68 if ( get_option( 'embedpress_activation_redirect_done' ) || wp_doing_ajax() ) {
69 return;
70 }
71
72
73 update_option( 'embedpress_activation_redirect_done', true );
74 $settings['need_first_time_redirect'] = false;
75 update_option( EMBEDPRESS_PLG_NAME, $settings);
76
77 if ( is_network_admin() || isset( $_GET['activate-multi'] ) ) {
78 return;
79 }
80
81 wp_safe_redirect( admin_url('admin.php?page='.$this->page_slug) );
82 exit;
83 }
84
85 }
86 public function update_elements_list() {
87 if ( !empty($_POST['_wpnonce'] && wp_verify_nonce( $_POST['_wpnonce'], 'embedpress_elements_action')) ) {
88 $option = EMBEDPRESS_PLG_NAME.":elements";
89 $elements = (array) get_option( $option, []);
90 $settings = (array) get_option( EMBEDPRESS_PLG_NAME, []);
91
92 $type = !empty( $_POST['element_type']) ? sanitize_text_field( $_POST['element_type']) : '';
93 $name = !empty( $_POST['element_name']) ? sanitize_text_field( $_POST['element_name']) : '';
94 $checked = !empty( $_POST['checked']) ? $_POST['checked'] : false;
95 if ( 'false' != $checked ) {
96 $elements[$type][$name] = $name;
97 if ( $type === 'classic' ) {
98 $settings[$name] = 1;
99 }
100 }else{
101 if( isset( $elements[$type]) && isset( $elements[$type][$name])){
102 unset( $elements[$type][$name]);
103 }
104 if ( $type === 'classic' ) {
105 $settings[$name] = 0;
106 }
107 }
108 update_option( EMBEDPRESS_PLG_NAME, $settings);
109 update_option( $option, $elements);
110 wp_send_json_success();
111 }
112 wp_send_json_error();
113 }
114
115 public function register_menu() {
116 add_menu_page( __('EmbedPress Settings', 'embedpress'), 'EmbedPress', 'manage_options', $this->page_slug,
117 [ $this, 'render_settings_page' ], null, 64 );
118
119 }
120
121 public function handle_scripts_and_styles() {
122 if ( !empty( $_REQUEST['page']) && $this->page_slug === $_REQUEST['page'] ) {
123 $this->enqueue_styles();
124 $this->enqueue_scripts();
125 }
126 }
127
128 public function enqueue_scripts() {
129 if ( !did_action( 'wp_enqueue_media') ) {
130 wp_enqueue_media();
131 }
132 wp_register_script( 'ep-settings-script', EMBEDPRESS_SETTINGS_ASSETS_URL.'js/settings.js', ['jquery', 'wp-color-picker' ], $this->file_version, true );
133 wp_enqueue_script( 'ep-settings', EMBEDPRESS_URL_ASSETS . 'js/settings.js', ['jquery', 'wp-color-picker' ], $this->file_version, true );
134 wp_localize_script( 'ep-settings-script', 'embedpressObj', array(
135 'nonce' => wp_create_nonce('embedpress_elements_action'),
136 ) );
137
138 wp_enqueue_script( 'ep-settings-script');
139 }
140
141 public function enqueue_styles() {
142 wp_enqueue_style( 'ep-settings-style', EMBEDPRESS_SETTINGS_ASSETS_URL.'css/style.css', null, $this->file_version );
143 wp_enqueue_style( 'ep-settings-icon-style', EMBEDPRESS_SETTINGS_ASSETS_URL.'css/icon/style.css', null, $this->file_version );
144 wp_enqueue_style( 'wp-color-picker' );
145
146 }
147
148 public function render_settings_page( ) {
149 $page_slug = $this->page_slug; // make this available for included template
150 $template = !empty( $_GET['page_type'] ) ? sanitize_text_field( $_GET['page_type']) : 'general';
151 $nonce_field = wp_nonce_field('ep_settings_nonce', 'ep_settings_nonce', true, false);
152 $ep_page = admin_url('admin.php?page='.$this->page_slug);
153 $gen_menu_template_names = apply_filters('ep_general_menu_tmpl_names', ['general', 'youtube', 'vimeo', 'wistia', 'twitch']);
154 $brand_menu_template_names = apply_filters('ep_brand_menu_templates', ['custom-logo', 'branding',]);
155 $pro_active = is_embedpress_pro_active();
156 $coming_soon = "<span class='ep-coming-soon'>". esc_html__( '(Coming soon)', 'embedpress'). "</span>";
157 $success_message = esc_html__( "Settings Updated", "embedpress" );
158 $error_message = esc_html__( "Ops! Something went wrong.", "embedpress" );
159 include_once EMBEDPRESS_SETTINGS_PATH . 'templates/main-template.php';
160 }
161
162 public function save_settings() {
163 if ( !empty( $_POST['ep_settings_nonce']) && wp_verify_nonce( $_POST['ep_settings_nonce'], 'ep_settings_nonce') ) {
164 $submit_type = !empty( $_POST['submit'] ) ? $_POST['submit'] : '';
165 $save_handler_method = "save_{$submit_type}_settings";
166 do_action( "before_{$save_handler_method}");
167 do_action( "before_embedpress_settings_save");
168 if ( method_exists( $this, $save_handler_method ) ) {
169 $this->$save_handler_method();
170 }
171 do_action( "after_embedpress_settings_save");
172 $return_url = isset( $_SERVER['HTTP_REFERER'] ) ? $_SERVER['HTTP_REFERER'] : admin_url();
173 $return_url = add_query_arg( 'success', 1, $return_url );
174 wp_safe_redirect( $return_url);
175 exit();
176 }
177 }
178
179 public function save_general_settings() {
180 $settings = (array) get_option( EMBEDPRESS_PLG_NAME);
181 $settings ['enableEmbedResizeWidth'] = isset( $_POST['enableEmbedResizeWidth']) ? intval( $_POST['enableEmbedResizeWidth']) : 600;
182 $settings ['enableEmbedResizeHeight'] = isset( $_POST['enableEmbedResizeHeight']) ? intval( $_POST['enableEmbedResizeHeight']) : 550;
183
184 // Pro will handle g_loading_animation settings and other
185 $settings = apply_filters( 'ep_general_settings_before_save', $settings, $_POST);
186
187 update_option( EMBEDPRESS_PLG_NAME, $settings);
188 do_action( 'ep_general_settings_after_save', $settings, $_POST);
189 }
190
191 public function save_youtube_settings() {
192 $option_name = EMBEDPRESS_PLG_NAME.':youtube';
193 $settings = get_option( $option_name);
194 $settings['autoplay'] = isset( $_POST['autoplay']) ? sanitize_text_field( $_POST['autoplay']) : '';
195 $settings['controls'] = isset( $_POST['controls']) ? sanitize_text_field( $_POST['controls']) : '';
196 $settings['fs'] = isset( $_POST['fs']) ? sanitize_text_field( $_POST['fs']) : '';
197 $settings['iv_load_policy'] = isset( $_POST['iv_load_policy']) ? sanitize_text_field( $_POST['iv_load_policy']) : 1;
198 $settings['license_key'] = 1; // backward compatibility
199
200 // Pro will handle g_loading_animation settings and other
201 $settings = apply_filters( 'ep_youtube_settings_before_save', $settings);
202 update_option( $option_name, $settings);
203 do_action( 'ep_youtube_settings_after_save', $settings);
204
205 }
206
207 public function save_wistia_settings() {
208 $option_name = EMBEDPRESS_PLG_NAME.':wistia';
209 $settings = get_option( $option_name);
210 $settings['autoplay'] = isset( $_POST['autoplay']) ? sanitize_text_field( $_POST['autoplay']) : '';
211 $settings['display_fullscreen_button'] = isset( $_POST['display_fullscreen_button']) ? sanitize_text_field( $_POST['display_fullscreen_button']) : '';
212 $settings['small_play_button'] = isset( $_POST['small_play_button']) ? sanitize_text_field( $_POST['small_play_button']) : '';
213 $settings['player_color'] = isset( $_POST['player_color']) ? sanitize_text_field( $_POST['player_color']) : '';
214 $settings['plugin_resumable'] = isset( $_POST['plugin_resumable']) ? sanitize_text_field( $_POST['plugin_resumable']) : '';
215 $settings['plugin_focus'] = isset( $_POST['plugin_focus']) ? sanitize_text_field( $_POST['plugin_focus']) : '';
216 $settings['license_key'] = 1; // backward compatibility
217 // Pro will handle g_loading_animation settings and other
218 $settings = apply_filters( 'ep_wistia_settings_before_save', $settings);
219 update_option( $option_name, $settings);
220 do_action( 'ep_wistia_settings_after_save', $settings);
221 }
222
223 public function save_vimeo_settings() {
224 $option_name = EMBEDPRESS_PLG_NAME.':vimeo';
225 $settings = get_option( $option_name);
226 $settings['autoplay'] = isset( $_POST['autoplay']) ? sanitize_text_field( $_POST['autoplay']) : '';
227 $settings['color'] = isset( $_POST['color']) ? sanitize_text_field( $_POST['color']) : '#00adef';
228 $settings['display_title'] = isset( $_POST['display_title']) ? sanitize_text_field( $_POST['display_title']) : 1;
229 $settings['license_key'] = 1; // backward compatibility
230 // Pro will handle g_loading_animation settings and other
231 $settings = apply_filters( 'ep_vimeo_settings_before_save', $settings);
232 update_option( $option_name, $settings);
233 do_action( 'ep_vimeo_settings_after_save', $settings);
234 }
235
236 public function save_twitch_settings() {
237 $option_name = EMBEDPRESS_PLG_NAME.':twitch';
238 $settings = get_option( $option_name);
239 $settings['embedpress_pro_twitch_autoplay'] = isset( $_POST['autoplay']) ? sanitize_text_field( $_POST['autoplay']) : 'no';
240 $settings['embedpress_pro_fs'] = isset( $_POST['fs']) ? sanitize_text_field( $_POST['fs']) : 'yes';
241 $settings['license_key'] = 1; // backward compatibility
242 // Pro will handle g_loading_animation settings and other
243 $settings = apply_filters( 'ep_twitch_settings_before_save', $settings);
244 update_option( $option_name, $settings);
245 do_action( 'ep_twitch_settings_after_save', $settings);
246 }
247
248 public function save_custom_logo_settings() {
249 do_action( 'before_embedpress_branding_save');
250 $settings = (array) get_option( EMBEDPRESS_PLG_NAME, []);
251 $settings['embedpress_document_powered_by'] = isset( $_POST['embedpress_document_powered_by']) ? sanitize_text_field( $_POST['embedpress_document_powered_by']) : 'no';
252 update_option( EMBEDPRESS_PLG_NAME, $settings);
253 do_action( 'after_embedpress_branding_save');
254
255 }
256 }