| @@ -46,8 +46,9 @@ | ||
| 46 | 46 | */ |
| 47 | 47 | public function hooks(){ |
| 48 | 48 | add_action( 'enqueue_block_editor_assets', [ $this, 'scripts' ] ); |
| 49 | 49 | add_action( 'admin_footer', [ $this, 'print_admin_js_template' ] ); |
| 50 | + add_action( 'wp_ajax_update_gutenberg_hide_buttons', [ $this, 'update_gutenberg_hide_buttons' ] ); // Register AJAX action | |
| 50 | 51 | } |
| 51 | 52 | |
| 52 | 53 | /** |
| 53 | 54 | * Assets Enqueueing |
| @@ -163,5 +164,25 @@ | ||
| 163 | 164 | $data['content'] = Utils::import_and_replace_attachments($data['content'], $postId); |
| 164 | 165 | return $data; |
| 165 | 166 | } |
| 166 | 167 | |
| 168 | + /** | |
| 169 | + * AJAX handler to update the option `templately-gutenberg-hide-buttons` | |
| 170 | + */ | |
| 171 | + public function update_gutenberg_hide_buttons() { | |
| 172 | + // Check nonce for security | |
| 173 | + check_ajax_referer( 'templately_nonce', 'nonce' ); | |
| 174 | + | |
| 175 | + // Get the new value from the AJAX request | |
| 176 | + $hide_buttons = isset($_GET['hide_buttons']) ? sanitize_text_field($_GET['hide_buttons']) : ''; | |
| 177 | + | |
| 178 | + // Update the option | |
| 179 | + update_option('templately-gutenberg-hide-buttons', $hide_buttons); | |
| 180 | + | |
| 181 | + $hide_buttons = get_option('templately-gutenberg-hide-buttons', 'no'); | |
| 182 | + $hide_buttons = $hide_buttons === 'yes' ? 'yes' : 'no'; | |
| 183 | + // Send a response back to the JavaScript | |
| 184 | + wp_send_json_success([ | |
| 185 | + 'hide_buttons' => $hide_buttons, | |
| 186 | + ]); | |
| 187 | + } | |
| 167 | 188 | } |