Apple_Actions\Index\Export::fetch_exporter PHP Méthode

fetch_exporter() public méthode

Fetches an instance of Exporter.
public fetch_exporter ( ) : Exporter
Résultat Apple_Exporter\Exporter
    public function fetch_exporter()
    {
        do_action('apple_news_do_fetch_exporter', $this->id);
        // Fetch WP_Post object, and all required post information to fill up the
        // Exporter_Content instance.
        $post = get_post($this->id);
        // Build the excerpt if required
        if (empty($post->post_excerpt)) {
            $excerpt = wp_trim_words(strip_tags(strip_shortcodes($post->post_content)), 55, '...');
        } else {
            $excerpt = strip_tags($post->post_excerpt);
        }
        // Get the post thumbnail
        $post_thumb = wp_get_attachment_url(get_post_thumbnail_id($this->id)) ?: null;
        // Build the byline
        $byline = $this->format_byline($post);
        // Filter each of our items before passing into the exporter class.
        $title = apply_filters('apple_news_exporter_title', $post->post_title, $post->ID);
        $excerpt = apply_filters('apple_news_exporter_excerpt', $excerpt, $post->ID);
        $post_thumb = apply_filters('apple_news_exporter_post_thumb', $post_thumb, $post->ID);
        $byline = apply_filters('apple_news_exporter_byline', $byline, $post->ID);
        // The post_content is not raw HTML, as WordPress editor cleans up
        // paragraphs and new lines, so we need to transform the content to
        // HTML. We use 'the_content' filter for that.
        $content = apply_filters('apple_news_exporter_content_pre', $post->post_content, $post->ID);
        $content = apply_filters('the_content', $content);
        $content = apply_filters('apple_news_exporter_content', $content, $post->ID);
        // Now pass all the variables into the Exporter_Content array.
        $base_content = new Exporter_Content($post->ID, $title, $content, $excerpt, $post_thumb, $byline, $this->fetch_content_settings());
        return new Exporter($base_content, null, $this->settings);
    }

Usage Example

 public function testBylineFormatWithHashtag()
 {
     $user_id = $this->factory->user->create(array('role' => 'administrator', 'display_name' => '#Testuser'));
     $title = 'My Title';
     $content = '<p>Lorem ipsum dolor sit amet, consectetur adipiscing elit. Cras tristique quis justo sit amet eleifend. Praesent id metus semper, fermentum nibh at, malesuada enim. Mauris eget faucibus lectus. Vivamus iaculis eget urna non porttitor. Donec in dignissim neque. Vivamus ut ornare magna. Nulla eros nisi, maximus nec neque at, condimentum lobortis leo. Fusce in augue arcu. Curabitur lacus elit, venenatis a laoreet sit amet, imperdiet ac lorem. Curabitur sed leo sed ligula tempor feugiat. Cras in tellus et elit volutpat.</p>';
     $post_id = $this->factory->post->create(array('post_title' => $title, 'post_content' => $content, 'post_excerpt' => '', 'post_author' => $user_id, 'post_date' => '2016-08-26 12:00'));
     $export = new Export($this->settings, $post_id);
     $exporter = $export->fetch_exporter();
     $exporter_content = $exporter->get_content();
     $this->assertEquals('by #Testuser | Aug 26, 2016 | 12:00 PM', $exporter_content->byline());
 }
All Usage Examples Of Apple_Actions\Index\Export::fetch_exporter