Changeset 2653314
- Timestamp:
- 01/05/2022 08:51:25 PM (4 years ago)
- Location:
- planetplanet
- Files:
-
- 3 edited
- 5 copied
-
tags/0.15 (copied) (copied from planetplanet/trunk)
-
tags/0.15/logger.php (copied) (copied from planetplanet/trunk/logger.php)
-
tags/0.15/planetplanet-cli.php (copied) (copied from planetplanet/trunk/planetplanet-cli.php) (1 diff)
-
tags/0.15/planetplanet.php (copied) (copied from planetplanet/trunk/planetplanet.php) (6 diffs)
-
tags/0.15/readme.txt (copied) (copied from planetplanet/trunk/readme.txt) (1 diff)
-
trunk/planetplanet-cli.php (modified) (1 diff)
-
trunk/planetplanet.php (modified) (6 diffs)
-
trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
planetplanet/tags/0.15/planetplanet-cli.php
r2653284 r2653314 306 306 307 307 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 ); 311 310 } 312 311 } -
planetplanet/tags/0.15/planetplanet.php
r2653284 r2653314 8 8 * Text Domain: planetplanet 9 9 * Domain Path: /languages 10 * Version: 0.1 410 * Version: 0.15 11 11 * 12 12 * @package Planetplanet … … 817 817 818 818 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 ); 820 825 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 ); 822 827 823 828 if ( $image_url ) { 824 829 $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 ) { 834 837 if ( empty($post->post_content ) ) return; 835 838 … … 859 862 860 863 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 ) { 866 865 if ( !$post->item_link ) return; 867 if ( has_post_thumbnail( $post ) ) return;868 866 869 867 $response = $this->get_web_page( $post->item_link ); … … 905 903 // Upload featured image from external site to an imported post 906 904 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 ) { 914 906 915 907 // Check if we already has that image saved … … 920 912 'meta_value' => $image_url, 921 913 ] ); 922 923 914 924 915 if ( empty( $images ) ) { … … 951 942 952 943 if ( $upload_file['error'] ) { 953 $this->logg ger->error( __( 'Image upload error %s', 'planetplanet' ), $upload_file['error'] );944 $this->logger->error( __( 'Image upload error %s', 'planetplanet' ), $upload_file['error'] ); 954 945 return; 955 946 } -
planetplanet/tags/0.15/readme.txt
r2653284 r2653314 5 5 Tested up to: 5.8 6 6 Requires PHP: 7.4 7 Stable tag: 0.1 47 Stable tag: 0.15 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html -
planetplanet/trunk/planetplanet-cli.php
r2653284 r2653314 306 306 307 307 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 ); 311 310 } 312 311 } -
planetplanet/trunk/planetplanet.php
r2653284 r2653314 8 8 * Text Domain: planetplanet 9 9 * Domain Path: /languages 10 * Version: 0.1 410 * Version: 0.15 11 11 * 12 12 * @package Planetplanet … … 817 817 818 818 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 ); 820 825 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 ); 822 827 823 828 if ( $image_url ) { 824 829 $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 ) { 834 837 if ( empty($post->post_content ) ) return; 835 838 … … 859 862 860 863 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 ) { 866 865 if ( !$post->item_link ) return; 867 if ( has_post_thumbnail( $post ) ) return;868 866 869 867 $response = $this->get_web_page( $post->item_link ); … … 905 903 // Upload featured image from external site to an imported post 906 904 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 ) { 914 906 915 907 // Check if we already has that image saved … … 920 912 'meta_value' => $image_url, 921 913 ] ); 922 923 914 924 915 if ( empty( $images ) ) { … … 951 942 952 943 if ( $upload_file['error'] ) { 953 $this->logg ger->error( __( 'Image upload error %s', 'planetplanet' ), $upload_file['error'] );944 $this->logger->error( __( 'Image upload error %s', 'planetplanet' ), $upload_file['error'] ); 954 945 return; 955 946 } -
planetplanet/trunk/readme.txt
r2653284 r2653314 5 5 Tested up to: 5.8 6 6 Requires PHP: 7.4 7 Stable tag: 0.1 47 Stable tag: 0.15 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html
Note: See TracChangeset
for help on using the changeset viewer.