public function test_iterator_processes_post_correctly()
 {
     $content_before = 'This is some content with a [shortcode] with nested shortcodes[shortcode] and a closing tag[/shortcode]';
     $content_expected = 'This is some content with a  with nested shortcodes and a closing tag';
     $post = new \WP_Post(new \stdClass());
     $post->post_content = $content_before;
     $iterator = new Iterator('shortcode');
     // Manually set the post object, so we don't need a DB to run the tests
     $iterator->current_post_object = $post;
     $iterator->process_post();
     $this->assertEquals($content_expected, $iterator->current_post_object->post_content);
 }
Esempio n. 2
0
 public function handle_ajax()
 {
     if (!current_user_can(SC\get_plugin('capability'))) {
         wp_send_json_error(array('message' => __('You do not have permission to remove shortcodes.', 'marslender-shortcode-cleaner')));
     }
     if (!isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], $this->nonce_action)) {
         wp_send_json_error(array('message' => __('Unable to verify request. Please try again.', 'marslender-shortcode-cleaner')));
     }
     if (!isset($_POST['shortcode']) || empty($_POST['shortcode'])) {
         wp_send_json_error(array('message' => __('You must provide a shortcode name.', 'marslender-shortcode-cleaner')));
     }
     if (!isset($_POST['post_types']) || empty($_POST['post_types'])) {
         wp_send_json_error(array('message' => __('You must provide post types to remove shortcodes from.', 'marslender-shortcode-cleaner')));
     }
     $shortcode = sanitize_text_field($_POST['shortcode']);
     $post_types = array_map('sanitize_text_field', (array) $_POST['post_types']);
     // @todo would be nice to integrate multiple post type support to post iterator
     foreach ($post_types as $post_type) {
         $iterator = new SC\Iterators\Iterator($shortcode, array('post_type' => $post_type));
         $iterator->go();
     }
     // @todo i18n
     wp_send_json_success(array('message' => "Successfully removed the {$shortcode} shortcode from the selected post types."));
 }