Changeset 2942170
- Timestamp:
- 07/23/2023 04:32:02 PM (3 years ago)
- Location:
- planetplanet/trunk
- Files:
-
- 3 edited
-
planetplanet-cli.php (modified) (2 diffs)
-
planetplanet.php (modified) (7 diffs)
-
readme.txt (modified) (3 diffs)
Legend:
- Unmodified
- Added
- Removed
-
planetplanet/trunk/planetplanet-cli.php
r2828210 r2942170 281 281 * : Update given posts 282 282 * 283 * [--force] 284 * : Force the change 285 * 283 286 * [--log-level=<level>] 284 287 * : Change the log-level from what is configured in the plugin … … 303 306 $planetplanet->set_loglevel( $assoc['log-level']); 304 307 308 $force = false; 309 if ( isset( $assoc['force'] ) ) 310 $force = true; 311 305 312 foreach ( $args as $arg ) { 306 313 WP_CLI::log( sprintf( __("Updating thumbnail for post %d", 'planetplanet' ), $arg ) ); 307 $planetplanet->add_featured_image( (int)$arg ); 314 315 $post_id = (int)$arg; 316 $image_url = NULL; 317 318 $cats = wp_get_post_categories( $post_id, [ 'fields' => 'all'] ); 319 if ( ! is_wp_error( $cats ) ) { 320 $link = $planetplanet->get_category_link_object( $cats[0] ); 321 322 if ( isset( $link ) ) 323 $image_url = $link->link_image; 324 } 325 326 if ( $force ) 327 delete_post_thumbnail( $post_id ); 328 329 $planetplanet->add_featured_image( $post_id, $image_url ); 308 330 } 309 331 } -
planetplanet/trunk/planetplanet.php
r2871308 r2942170 8 8 * Text Domain: planetplanet 9 9 * Domain Path: /languages 10 * Version: 0.1 810 * Version: 0.19 11 11 * 12 12 * @package Planetplanet … … 124 124 function get_option( $name ) { 125 125 $options = get_option( 'planetplanet_options' ); 126 if ( empty( $options ) ) return NULL; 126 127 if ( array_key_exists( $name, $options ) ) return $options[$name]; 127 128 if ( array_key_exists( "planetplanet_$name", $options ) ) return $options["planetplanet_$name"]; … … 720 721 } 721 722 722 function get_category_link ( $cat ) {723 function get_category_link_object( $cat ) { 723 724 $linkmap = get_transient( 'planetplanet_category_linkmap' ); 724 725 725 if ( isset( $linkmap ) and isset( $linkmap[$cat->term_id] ) ) 726 return $linkmap[$cat->term_id]; 726 $cat_id = $cat->term_id; 727 728 if ( isset( $linkmap ) and isset( $linkmap[$cat_id] ) ) 729 return $linkmap[$cat_id]; 727 730 728 731 $linkmap = []; … … 732 735 733 736 if ( $linkcat ) 734 $linkmap[$linkcat->term_id] = $link ->link_url;737 $linkmap[$linkcat->term_id] = $link; 735 738 } 736 739 set_transient( 'planetplanet_category_linkmap', $linkmap ); 737 740 738 return isset( $linkmap[$cat->term_id] ) ? $linkmap[$cat->term_id] : NULL; 741 return isset( $linkmap[$cat_id] ) ? $linkmap[$cat_id] : NULL; 742 } 743 744 function get_category_link( $cat ) { 745 $link = $this->get_category_link_object( $cat ); 746 return isset( $link ) ? $link->link_url : NULL; 739 747 } 740 748 … … 805 813 806 814 // Add feature image if found 807 $this->add_featured_image( $post_id );815 $this->add_featured_image( $post_id, $link->link_image ); 808 816 } 809 817 … … 817 825 } 818 826 819 function add_featured_image( $post_id ) {827 function add_featured_image( $post_id, $image_url = NULL ) { 820 828 $post = get_post( (int)$post_id ); 821 829 … … 823 831 if ( has_post_thumbnail( $post ) ) return; 824 832 825 $image_url = $this->get_featured_image_from_content( $post ); 833 if ( empty( $image_url ) ) 834 $image_url = $this->get_featured_image_from_content( $post ); 826 835 if ( empty( $image_url ) ) 827 836 $image_url = $this->get_featured_image_from_original_post( $post ); -
planetplanet/trunk/readme.txt
r2942102 r2942170 5 5 Tested up to: 6.3 6 6 Requires PHP: 7.4 7 Stable tag: 0.1 87 Stable tag: 0.19 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html … … 30 30 31 31 Implementation notes: feeds errors are counted in the link_rating field, and the feed is marked not visible if it generates too many errors. 32 33 The fields in the Links section are used like this: 34 * Name: site title 35 * Web address: main site url 36 * Advanced / Image Address: featured image override url 37 * Advanced / RSS Address: site feed url 38 * Advanced / Notes: last update time or last error message 39 * Advanced / Rating: error count 40 * Keep this link private: private links are ignored 32 41 33 42 == Installation == … … 79 88 == Changelog == 80 89 90 = 0.19 = 91 * Tested with WP 6.3rc1 92 * Fixed a bug in first time activation 93 * Link field 'link_image' can be used to override site thumbnail 94 81 95 = 0.13 = 82 96 * First published version.
Note: See TracChangeset
for help on using the changeset viewer.