Plugin Directory

Changeset 2612027


Ignore:
Timestamp:
10/10/2021 09:36:08 AM (4 years ago)
Author:
resoc
Message:

Version 1.0.12

Location:
resoc
Files:
22 added
6 edited

Legend:

Unmodified
Added
Removed
  • resoc/trunk/README.txt

    r2585348 r2612027  
    55Requires at least: 5.0
    66Tested up to: 5.8
    7 Stable tag: 1.0.11
     7Stable tag: 1.0.12
    88License: GPLv2 or later
    99License URI: http://www.gnu.org/licenses/gpl-2.0.html
     
    76761. Without Resoc, your content is mundane when it is shared on Facebook. With Resoc, your audience notices it.
    77772. After activation, visit 'Appearance > Social Images' to select the template, colors and logo.
    78 3. The editor is unchanged. Here, the featured image of the post is a beautiful bridge... But it says nothing about your post or brand.
     783. In addition to the classic featured image, the editor now shows your social image.
    79794. When a visitor shares your post on Facebook, his/her friends immediately notice your post title and your logo.
    8080
    8181== Changelog ==
     82
     83= 1.0.12 =
     84* Social image preview
     85* Fix: different file name for each image
     86* Fix: regenerate social image on featured image change
    8287
    8388= 1.0.11 =
  • resoc/trunk/admin/class-resoc-admin.php

    r2556202 r2612027  
    5656      array( $this, 'save_social_image' ) );
    5757
     58    add_action( 'updated_post_meta',
     59      array( $this, 'metadata_updated' ), 10, 3 );
     60
    5861    add_action( 'admin_notices', array( $this, 'finish_setup_notice' ));
    5962
    6063    add_filter('plugin_action_links', array( $this, 'plugin_action_links' ), 10, 2);
     64
     65    add_action( 'init', array( $this, 'register_preview_script' ) );
     66
     67    add_action( 'enqueue_block_editor_assets', array( $this, 'enqueue_preview_script' ) );
     68  }
     69
     70  public function register_preview_script() {
     71    wp_register_script(
     72      'preview-metabox-js',
     73      plugins_url( 'js/preview-metabox.js', __FILE__ ),
     74      array( 'wp-plugins', 'wp-edit-post', 'wp-element' )
     75    );
     76  }
     77
     78  public function enqueue_preview_script() {
     79    wp_enqueue_script( 'preview-metabox-js' );
     80
     81    $options = get_option( Resoc_Settings::OPTIONS );
     82
     83    $scriptData = array(
     84      'templatesBaseUrl' => plugins_url('', __FILE__),
     85      'template' => $options[ Resoc_Settings::TEMPLATE ],
     86      'backgroundColor' => $options[ Resoc_Settings::BACKGROUND_COLOR ],
     87      'textColor' => $options[ Resoc_Settings::TEXT_COLOR ],
     88      'brandName' => $options[ Resoc_Settings::BRAND_NAME ],
     89      'textDirection' => isset( $options[ Resoc_Settings::TEXT_DIRECTION ] )
     90        ? $options[ Resoc_Settings::TEXT_DIRECTION ]
     91        : 'ltr',
     92        'brandName' => $options[ Resoc_Settings::BRAND_NAME ],
     93      'logoUrl' => wp_get_attachment_url( $options[ Resoc_Settings::LOGO ] )
     94    );
     95
     96    wp_localize_script('preview-metabox-js', 'template_options', $scriptData);
    6197  }
    6298
     
    76112  }
    77113
     114  public function metadata_updated( $meta_ID, $post_ID, $meta_key ) {
     115    if ( $meta_key == '_thumbnail_id' ) {
     116      Resoc_Utils::log( "Thumbnail image of post " . $post_ID  . " was updated, regenerate its social image" );
     117      $this->generate_image_for_post( get_post( $post_ID ) );
     118    }
     119  }
     120
    78121  public function save_social_image( $post_ID ) {
    79122    Resoc_Utils::log( "Generate social images for post " . $post_ID );
     
    85128    }
    86129
    87     $feature_image_url = Resoc_Utils::get_post_featured_image_url( $post_ID );
     130    $this->generate_image_for_post( $post );
     131  }
     132
     133  public function generate_image_for_post( $post ) {
     134    $feature_image_url = Resoc_Utils::get_post_featured_image_url( $post->ID );
    88135    if ( !$feature_image_url ) {
    89       Resoc_Utils::log( "Cannot get featured image for post " . $post_ID );
     136      Resoc_Utils::log( "Cannot get featured image for post " . $post->ID );
    90137      return;
    91138    }
     
    119166
    120167    $current_request_hash = Resoc_Utils::hash_request( $request );
    121     $previous_request_hash = get_post_meta( $post_ID, Resoc::POST_META_LATEST_REQUEST_HASH, true );
     168    $previous_request_hash = get_post_meta( $post->ID, Resoc::POST_META_LATEST_REQUEST_HASH, true );
    122169    if ( $previous_request_hash && $previous_request_hash == $current_request_hash ) {
    123170      Resoc_Utils::log( "No change since the last time the image was generated, do nothing" );
     
    127174    $social_image = Resoc_Utils::create_social_image( $request );
    128175    if ( !$social_image ) {
    129       Resoc_Utils::log( "Cannot generate social image for post " . $post_ID );
     176      Resoc_Utils::log( "Cannot generate social image for post " . $post->ID );
    130177      return;
    131178    }
    132179
    133180    // Get existing OpenGraph image to update it as an attachement
    134     $existing_og_image_id = get_post_meta( $post_ID, Resoc::POST_META_OG_IMAGE_ID, true );
    135 
    136     $social_image_id = Resoc_Utils::add_image_to_media_library( $social_image, $post_ID, $existing_og_image_id );
     181    $existing_og_image_id = get_post_meta( $post->ID, Resoc::POST_META_OG_IMAGE_ID, true );
     182
     183    $social_image_id = Resoc_Utils::add_image_to_media_library( $social_image, $post->ID, $existing_og_image_id );
    137184    if ( !$social_image_id ) {
    138       Resoc_Utils::log( "Cannot store/attach social image for post " . $post_ID );
    139       return;
    140     }
    141 
    142     update_post_meta( $post_ID, Resoc::POST_META_OG_IMAGE_ID, $social_image_id );
    143 
    144     update_post_meta( $post_ID, Resoc::POST_META_LATEST_REQUEST_HASH, $current_request_hash );
    145 
    146     Resoc_Utils::log( "OpenGraph image " . $social_image_id . " attached to post " . $post_ID );
     185      Resoc_Utils::log( "Cannot store/attach social image for post " . $post->ID );
     186      return;
     187    }
     188
     189    update_post_meta( $post->ID, Resoc::POST_META_OG_IMAGE_ID, $social_image_id );
     190
     191    update_post_meta( $post->ID, Resoc::POST_META_LATEST_REQUEST_HASH, $current_request_hash );
     192
     193    Resoc_Utils::log( "OpenGraph image " . $social_image_id . " attached to post " . $post->ID );
    147194  }
    148195
     
    211258
    212259        wp_enqueue_script( $this->resoc, plugin_dir_url( __FILE__ ) . 'js/resoc-admin.js', array( 'jquery' ), $this->version, false );
    213 
    214260    }
    215261
  • resoc/trunk/includes/class-resoc-utils.php

    r2548933 r2612027  
    7171  }
    7272
    73   public static function add_image_to_media_library( $image_data, $post_ID, $attach_id = NULL, $filename = 'og-image.jpg' ) {
     73  public static function og_image_filename( $post_ID ) {
     74    return 'og-image-' . $post_ID . '.jpg';
     75  }
     76
     77  public static function add_image_to_media_library( $image_data, $post_ID, $attach_id = NULL, $filename = NULL) {
    7478    $upload_dir = wp_upload_dir();
     79
     80    if ( !$filename ) {
     81      $filename = Resoc_Utils::og_image_filename( $post_ID );
     82    }
    7583
    7684    // If an existing attachement exists, take its file path and name.
  • resoc/trunk/resoc.php

    r2585348 r2612027  
    1717 * Plugin URI:        https://resoc.io/resoc-uri/
    1818 * Description:       Improve the images used to illustrate your content when it is share on social networks and messaging services.
    19  * Version:           1.0.11
     19 * Version:           1.0.12
    2020 * Author:            Resoc
    2121 * Author URI:        https://resoc.io/
     
    3636 * Rename this for your plugin and update it as you release new versions.
    3737 */
    38 define( 'RESOC_VERSION', '1.0.11' );
     38define( 'RESOC_VERSION', '1.0.12' );
    3939
    4040/**
Note: See TracChangeset for help on using the changeset viewer.