Changeset 2612027
- Timestamp:
- 10/10/2021 09:36:08 AM (4 years ago)
- Location:
- resoc
- Files:
-
- 22 added
- 6 edited
-
assets/banner-772x250.png (modified) (previous)
-
assets/screenshot-3.png (modified) (previous)
-
trunk/README.txt (modified) (2 diffs)
-
trunk/admin/class-resoc-admin.php (modified) (6 diffs)
-
trunk/admin/js/preview-metabox.js (added)
-
trunk/admin/templates (added)
-
trunk/admin/templates/basic01 (added)
-
trunk/admin/templates/basic01/content.html.mustache (added)
-
trunk/admin/templates/basic01/resoc.manifest.json (added)
-
trunk/admin/templates/basic01/styles.css.mustache (added)
-
trunk/admin/templates/basic01/textFit.js (added)
-
trunk/admin/templates/basic02 (added)
-
trunk/admin/templates/basic02/content.html.mustache (added)
-
trunk/admin/templates/basic02/resoc.manifest.json (added)
-
trunk/admin/templates/basic02/styles.css.mustache (added)
-
trunk/admin/templates/basic02/textFit.js (added)
-
trunk/admin/templates/basic03 (added)
-
trunk/admin/templates/basic03/content.html.mustache (added)
-
trunk/admin/templates/basic03/resoc.manifest.json (added)
-
trunk/admin/templates/basic03/styles.css.mustache (added)
-
trunk/admin/templates/basic03/textFit.js (added)
-
trunk/admin/templates/basic04 (added)
-
trunk/admin/templates/basic04/content.html.mustache (added)
-
trunk/admin/templates/basic04/resoc.manifest.json (added)
-
trunk/admin/templates/basic04/styles.css.mustache (added)
-
trunk/admin/templates/basic04/textFit.js (added)
-
trunk/includes/class-resoc-utils.php (modified) (1 diff)
-
trunk/resoc.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
resoc/trunk/README.txt
r2585348 r2612027 5 5 Requires at least: 5.0 6 6 Tested up to: 5.8 7 Stable tag: 1.0.1 17 Stable tag: 1.0.12 8 8 License: GPLv2 or later 9 9 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 76 76 1. Without Resoc, your content is mundane when it is shared on Facebook. With Resoc, your audience notices it. 77 77 2. 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.78 3. In addition to the classic featured image, the editor now shows your social image. 79 79 4. When a visitor shares your post on Facebook, his/her friends immediately notice your post title and your logo. 80 80 81 81 == 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 82 87 83 88 = 1.0.11 = -
resoc/trunk/admin/class-resoc-admin.php
r2556202 r2612027 56 56 array( $this, 'save_social_image' ) ); 57 57 58 add_action( 'updated_post_meta', 59 array( $this, 'metadata_updated' ), 10, 3 ); 60 58 61 add_action( 'admin_notices', array( $this, 'finish_setup_notice' )); 59 62 60 63 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); 61 97 } 62 98 … … 76 112 } 77 113 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 78 121 public function save_social_image( $post_ID ) { 79 122 Resoc_Utils::log( "Generate social images for post " . $post_ID ); … … 85 128 } 86 129 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 ); 88 135 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 ); 90 137 return; 91 138 } … … 119 166 120 167 $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 ); 122 169 if ( $previous_request_hash && $previous_request_hash == $current_request_hash ) { 123 170 Resoc_Utils::log( "No change since the last time the image was generated, do nothing" ); … … 127 174 $social_image = Resoc_Utils::create_social_image( $request ); 128 175 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 ); 130 177 return; 131 178 } 132 179 133 180 // 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 ); 137 184 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 ); 147 194 } 148 195 … … 211 258 212 259 wp_enqueue_script( $this->resoc, plugin_dir_url( __FILE__ ) . 'js/resoc-admin.js', array( 'jquery' ), $this->version, false ); 213 214 260 } 215 261 -
resoc/trunk/includes/class-resoc-utils.php
r2548933 r2612027 71 71 } 72 72 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) { 74 78 $upload_dir = wp_upload_dir(); 79 80 if ( !$filename ) { 81 $filename = Resoc_Utils::og_image_filename( $post_ID ); 82 } 75 83 76 84 // If an existing attachement exists, take its file path and name. -
resoc/trunk/resoc.php
r2585348 r2612027 17 17 * Plugin URI: https://resoc.io/resoc-uri/ 18 18 * Description: Improve the images used to illustrate your content when it is share on social networks and messaging services. 19 * Version: 1.0.1 119 * Version: 1.0.12 20 20 * Author: Resoc 21 21 * Author URI: https://resoc.io/ … … 36 36 * Rename this for your plugin and update it as you release new versions. 37 37 */ 38 define( 'RESOC_VERSION', '1.0.1 1' );38 define( 'RESOC_VERSION', '1.0.12' ); 39 39 40 40 /**
Note: See TracChangeset
for help on using the changeset viewer.