Plugin Directory

Changeset 2653314


Ignore:
Timestamp:
01/05/2022 08:51:25 PM (4 years ago)
Author:
seindal
Message:

Version 0.15

Location:
planetplanet
Files:
3 edited
5 copied

Legend:

Unmodified
Added
Removed
  • planetplanet/tags/0.15/planetplanet-cli.php

    r2653284 r2653314  
    306306
    307307        foreach ( $args as $arg ) {
    308             if ( is_int( $arg ) ) {
    309                 $planetplanet->add_featured_image( $arg );
    310             }
     308            WP_CLI::log( sprintf( __("Updating thumbnail for post %d", 'planetplanet' ), $arg ) );
     309            $planetplanet->add_featured_image( (int)$arg );
    311310        }
    312311    }
  • planetplanet/tags/0.15/planetplanet.php

    r2653284 r2653314  
    88 * Text Domain:     planetplanet
    99 * Domain Path:     /languages
    10  * Version:         0.14
     10 * Version:         0.15
    1111 *
    1212 * @package         Planetplanet
     
    817817
    818818    function add_featured_image( $post_id ) {
    819         $image_url = $this->get_featured_image_from_content( $post_id );
     819        $post = get_post( (int)$post_id );
     820
     821        if ( !$post ) return;
     822        if ( has_post_thumbnail( $post ) ) return;
     823
     824        $image_url = $this->get_featured_image_from_content( $post );
    820825        if ( empty( $image_url ) )
    821             $image_url = $this->get_featured_image_from_original_post( $post_id );
     826            $image_url = $this->get_featured_image_from_original_post( $post );
    822827
    823828        if ( $image_url ) {
    824829            $this->logger->debug( __( 'Found image url %s', 'planetplanet' ), $image_url );
    825             $this->upload_media( $post_id, $image_url );
    826         }
    827     }
    828 
    829     function get_featured_image_from_content( $post_id ) {
    830         if ( !$post_id ) return;
    831 
    832         $post = get_post( $post_id );
    833         if ( !$post ) return;
     830            $this->upload_media( $post, $image_url );
     831        } else {
     832            $this->logger->debug( __( 'No image found', 'planetplanet' ) );
     833        }
     834    }
     835
     836    function get_featured_image_from_content( $post ) {
    834837        if ( empty($post->post_content ) ) return;
    835838
     
    859862
    860863
    861     function get_featured_image_from_original_post( $post_id ) {
    862         if ( !$post_id ) return;
    863 
    864         $post = get_post( $post_id );
    865         if ( !$post ) return;
     864    function get_featured_image_from_original_post( $post ) {
    866865        if ( !$post->item_link ) return;
    867         if ( has_post_thumbnail( $post ) ) return;
    868866
    869867        $response = $this->get_web_page( $post->item_link );
     
    905903    // Upload featured image from external site to an imported post
    906904
    907     function upload_media( $post_id, $image_url ) {
    908         if ( !$post_id ) return;
    909 
    910         $post = get_post( $post_id );
    911         if ( !$post ) return;
    912 
    913         if ( has_post_thumbnail( $post ) ) return;
     905    function upload_media( $post, $image_url ) {
    914906
    915907        // Check if we already has that image saved
     
    920912            'meta_value' => $image_url,
    921913        ] );
    922 
    923914
    924915        if ( empty( $images ) ) {
     
    951942
    952943            if ( $upload_file['error'] ) {
    953                 $this->loggger->error( __( 'Image upload error %s', 'planetplanet' ), $upload_file['error'] );
     944                $this->logger->error( __( 'Image upload error %s', 'planetplanet' ), $upload_file['error'] );
    954945                return;
    955946            }
  • planetplanet/tags/0.15/readme.txt

    r2653284 r2653314  
    55Tested up to: 5.8
    66Requires PHP: 7.4
    7 Stable tag: 0.14
     7Stable tag: 0.15
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
  • planetplanet/trunk/planetplanet-cli.php

    r2653284 r2653314  
    306306
    307307        foreach ( $args as $arg ) {
    308             if ( is_int( $arg ) ) {
    309                 $planetplanet->add_featured_image( $arg );
    310             }
     308            WP_CLI::log( sprintf( __("Updating thumbnail for post %d", 'planetplanet' ), $arg ) );
     309            $planetplanet->add_featured_image( (int)$arg );
    311310        }
    312311    }
  • planetplanet/trunk/planetplanet.php

    r2653284 r2653314  
    88 * Text Domain:     planetplanet
    99 * Domain Path:     /languages
    10  * Version:         0.14
     10 * Version:         0.15
    1111 *
    1212 * @package         Planetplanet
     
    817817
    818818    function add_featured_image( $post_id ) {
    819         $image_url = $this->get_featured_image_from_content( $post_id );
     819        $post = get_post( (int)$post_id );
     820
     821        if ( !$post ) return;
     822        if ( has_post_thumbnail( $post ) ) return;
     823
     824        $image_url = $this->get_featured_image_from_content( $post );
    820825        if ( empty( $image_url ) )
    821             $image_url = $this->get_featured_image_from_original_post( $post_id );
     826            $image_url = $this->get_featured_image_from_original_post( $post );
    822827
    823828        if ( $image_url ) {
    824829            $this->logger->debug( __( 'Found image url %s', 'planetplanet' ), $image_url );
    825             $this->upload_media( $post_id, $image_url );
    826         }
    827     }
    828 
    829     function get_featured_image_from_content( $post_id ) {
    830         if ( !$post_id ) return;
    831 
    832         $post = get_post( $post_id );
    833         if ( !$post ) return;
     830            $this->upload_media( $post, $image_url );
     831        } else {
     832            $this->logger->debug( __( 'No image found', 'planetplanet' ) );
     833        }
     834    }
     835
     836    function get_featured_image_from_content( $post ) {
    834837        if ( empty($post->post_content ) ) return;
    835838
     
    859862
    860863
    861     function get_featured_image_from_original_post( $post_id ) {
    862         if ( !$post_id ) return;
    863 
    864         $post = get_post( $post_id );
    865         if ( !$post ) return;
     864    function get_featured_image_from_original_post( $post ) {
    866865        if ( !$post->item_link ) return;
    867         if ( has_post_thumbnail( $post ) ) return;
    868866
    869867        $response = $this->get_web_page( $post->item_link );
     
    905903    // Upload featured image from external site to an imported post
    906904
    907     function upload_media( $post_id, $image_url ) {
    908         if ( !$post_id ) return;
    909 
    910         $post = get_post( $post_id );
    911         if ( !$post ) return;
    912 
    913         if ( has_post_thumbnail( $post ) ) return;
     905    function upload_media( $post, $image_url ) {
    914906
    915907        // Check if we already has that image saved
     
    920912            'meta_value' => $image_url,
    921913        ] );
    922 
    923914
    924915        if ( empty( $images ) ) {
     
    951942
    952943            if ( $upload_file['error'] ) {
    953                 $this->loggger->error( __( 'Image upload error %s', 'planetplanet' ), $upload_file['error'] );
     944                $this->logger->error( __( 'Image upload error %s', 'planetplanet' ), $upload_file['error'] );
    954945                return;
    955946            }
  • planetplanet/trunk/readme.txt

    r2653284 r2653314  
    55Tested up to: 5.8
    66Requires PHP: 7.4
    7 Stable tag: 0.14
     7Stable tag: 0.15
    88License: GPLv2 or later
    99License URI: https://www.gnu.org/licenses/gpl-2.0.html
Note: See TracChangeset for help on using the changeset viewer.