Changeset 3261851
- Timestamp:
- 03/26/2025 12:42:28 AM (10 months ago)
- Location:
- dynamic-video-for-divi-posts
- Files:
-
- 11 added
- 4 edited
-
assets/screenshot-1.jpg (modified) (previous)
-
tags/1.0.2 (added)
-
tags/1.0.2/assets (added)
-
tags/1.0.2/assets/banner-1544x500.png (added)
-
tags/1.0.2/assets/banner-772x250.png (added)
-
tags/1.0.2/assets/icon-128x128.png (added)
-
tags/1.0.2/assets/icon-256x256.png (added)
-
tags/1.0.2/assets/screenshot-1.jpg (added)
-
tags/1.0.2/assets/screenshot-2.jpg (added)
-
tags/1.0.2/assets/screenshot-3.jpg (added)
-
tags/1.0.2/dynamic-video-for-divi-posts.php (added)
-
tags/1.0.2/readme.txt (added)
-
trunk/assets/screenshot-1.jpg (modified) (previous)
-
trunk/dynamic-video-for-divi-posts.php (modified) (6 diffs)
-
trunk/readme.txt (modified) (4 diffs)
Legend:
- Unmodified
- Added
- Removed
-
dynamic-video-for-divi-posts/trunk/dynamic-video-for-divi-posts.php
r3261070 r3261851 2 2 /* 3 3 Plugin Name: Dynamic Video for Divi Posts 4 Description: Dynamically embeds a video into your blog posts by using a custom field. When editing a post, a new meta box labeled "Video URL" appears. Enter a video URL (e.g., a YouTube link) into this box, and then use the [dynamic_video] shortcode in your Divi Builder template. The video is automatically embedded using WordPress’s oEmbed functionality. 5 Version: 1.0. 14 Description: Dynamically embeds a video into your blog posts by using a custom field. When editing a post, a new meta box labeled "Video URL" appears. Enter a video URL (e.g., a YouTube link) into this box, and then use the [dynamic_video] shortcode in your Divi Builder template. The video is automatically embedded using WordPress’s oEmbed functionality. Optional feature to display featured image when no video URL is provided. 5 Version: 1.0.2 6 6 Author: hyperspective 7 Author URI: https://hyperspective.com 8 Plugin URI: https://wordpress.org/plugins/dynamic-video-for-divi-posts/ 7 9 License: GPL2 8 10 License URI: http://www.gnu.org/licenses/gpl-2.0.html … … 10 12 11 13 if ( ! defined( 'ABSPATH' ) ) { 12 exit;14 exit; 13 15 } 14 16 15 17 /** 16 * Display the video via shortcode.18 * Display the video or featured image via shortcode. 17 19 * 18 20 * @param array $atts Shortcode attributes. 19 * @return string Embedded video HTML or empty string.21 * @return string Embedded video HTML, featured image HTML, or empty string. 20 22 */ 21 23 function dynvid_display_video_shortcode( $atts ) { 22 global $post; 23 $video_url = get_post_meta( $post->ID, '_dynvid_video_url', true ); 24 if ( empty( $video_url ) ) { 25 return ''; 26 } 27 // Embed the video using WordPress's oEmbed functionality. 28 return wp_oembed_get( esc_url( $video_url ) ); 24 global $post; 25 $video_url = get_post_meta( $post->ID, '_dynvid_video_url', true ); 26 27 if ( ! empty( $video_url ) ) { 28 // Embed the video using WordPress's oEmbed functionality. 29 return wp_oembed_get( esc_url( $video_url ) ); 30 } elseif ( get_option( 'dynvid_use_featured_image', 'no' ) === 'yes' ) { 31 // If no video URL and featured image option is enabled, display featured image 32 if ( has_post_thumbnail( $post->ID ) ) { 33 return get_the_post_thumbnail( $post->ID, 'full', array( 'class' => 'dynvid-featured-image' ) ); 34 } 35 } 36 return ''; 29 37 } 30 38 add_shortcode( 'dynamic_video', 'dynvid_display_video_shortcode' ); … … 34 42 */ 35 43 function dynvid_add_video_metabox() { 36 add_meta_box(37 'dynvid_video_metabox',38 esc_html__( 'Video URL', 'dynamic-video-for-divi-posts' ),39 'dynvid_video_url_metabox_callback',40 'post',41 'side',42 'default'43 );44 add_meta_box( 45 'dynvid_video_metabox', 46 esc_html__( 'Video URL', 'dynamic-video-for-divi-posts' ), 47 'dynvid_video_url_metabox_callback', 48 'post', 49 'side', 50 'default' 51 ); 44 52 } 45 53 add_action( 'add_meta_boxes', 'dynvid_add_video_metabox' ); … … 51 59 */ 52 60 function dynvid_video_url_metabox_callback( $post ) { 53 // Add nonce for security. 54 wp_nonce_field( 'dynvid_video_url_save', 'dynvid_video_url_nonce' ); 55 $video_url = get_post_meta( $post->ID, '_dynvid_video_url', true ); 56 ?> 57 <p> 58 <label for="dynvid_video_url"><?php esc_html_e( 'Enter the video URL (e.g., YouTube):', 'dynamic-video-for-divi-posts' ); ?></label> 59 </p> 60 <p> 61 <input type="text" name="dynvid_video_url" id="dynvid_video_url" value="<?php echo esc_attr( $video_url ); ?>" style="width:100%;" /> 62 </p> 63 <?php 61 wp_nonce_field( 'dynvid_video_url_save', 'dynvid_video_url_nonce' ); 62 $video_url = get_post_meta( $post->ID, '_dynvid_video_url', true ); 63 ?> 64 <p> 65 <label for="dynvid_video_url"><?php esc_html_e( 'Enter the video URL (e.g., YouTube):', 'dynamic-video-for-divi-posts' ); ?></label> 66 </p> 67 <p> 68 <input type="text" name="dynvid_video_url" id="dynvid_video_url" value="<?php echo esc_attr( $video_url ); ?>" style="width:100%;" /> 69 </p> 70 <?php 64 71 } 65 72 … … 70 77 */ 71 78 function dynvid_save_video_url_meta( $post_id ) { 72 // Check if nonce is set and valid. 73 if ( ! isset( $_POST['dynvid_video_url_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['dynvid_video_url_nonce'] ) ), 'dynvid_video_url_save' ) ) { 74 return; 75 } 76 // Check for autosave. 77 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { 78 return; 79 } 80 // Verify user permissions. 81 if ( isset( $_POST['post_type'] ) && 'post' === $_POST['post_type'] ) { 82 if ( ! current_user_can( 'edit_post', $post_id ) ) { 83 return; 84 } 85 } 86 if ( ! isset( $_POST['dynvid_video_url'] ) ) { 87 return; 88 } 89 // Sanitize and update the video URL. 90 $video_url = sanitize_text_field( wp_unslash( $_POST['dynvid_video_url'] ) ); 91 update_post_meta( $post_id, '_dynvid_video_url', esc_url_raw( $video_url ) ); 79 if ( ! isset( $_POST['dynvid_video_url_nonce'] ) || ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['dynvid_video_url_nonce'] ) ), 'dynvid_video_url_save' ) ) { 80 return; 81 } 82 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { 83 return; 84 } 85 if ( isset( $_POST['post_type'] ) && 'post' === $_POST['post_type'] ) { 86 if ( ! current_user_can( 'edit_post', $post_id ) ) { 87 return; 88 } 89 } 90 if ( ! isset( $_POST['dynvid_video_url'] ) ) { 91 return; 92 } 93 $video_url = sanitize_text_field( wp_unslash( $_POST['dynvid_video_url'] ) ); 94 update_post_meta( $post_id, '_dynvid_video_url', esc_url_raw( $video_url ) ); 92 95 } 93 96 add_action( 'save_post', 'dynvid_save_video_url_meta' ); 94 97 95 98 /** 96 * Add an admin submenu page for plugin details .99 * Add an admin submenu page for plugin details and settings. 97 100 */ 98 101 function dynvid_add_admin_menu() { 99 add_submenu_page(100 'options-general.php',101 esc_html__( 'Dynamic Video for Divi Posts Details', 'dynamic-video-for-divi-posts' ),102 esc_html__( 'Dynamic Video for Divi Posts', 'dynamic-video-for-divi-posts' ),103 'manage_options',104 'dynvid_plugin_details_page',105 'dynvid_plugin_details_page'106 );102 add_submenu_page( 103 'options-general.php', 104 esc_html__( 'Dynamic Video for Divi Posts Details', 'dynamic-video-for-divi-posts' ), 105 esc_html__( 'Dynamic Video for Divi Posts', 'dynamic-video-for-divi-posts' ), 106 'manage_options', 107 'dynvid_plugin_details_page', 108 'dynvid_plugin_details_page' 109 ); 107 110 } 108 111 add_action( 'admin_menu', 'dynvid_add_admin_menu' ); 112 113 /** 114 * Register settings for the plugin. 115 */ 116 function dynvid_register_settings() { 117 register_setting( 'dynvid_settings_group', 'dynvid_use_featured_image', array( 118 'type' => 'string', 119 'sanitize_callback' => 'sanitize_text_field', 120 'default' => 'no' 121 )); 122 } 123 add_action( 'admin_init', 'dynvid_register_settings' ); 109 124 110 125 /** … … 112 127 */ 113 128 function dynvid_plugin_details_page() { 114 ?> 115 <div class="wrap"> 116 <h1><?php esc_html_e( 'Dynamic Video for Divi Posts Details', 'dynamic-video-for-divi-posts' ); ?></h1> 117 <p><?php esc_html_e( 'This plugin dynamically embeds a video into your blog posts using a custom field. When editing a post, enter a video URL (e.g., a YouTube link) in the Video URL meta box, and then use the [dynamic_video] shortcode in your Divi Builder template to display the video.', 'dynamic-video-for-divi-posts' ); ?></p> 118 <h2><?php esc_html_e( 'Usage Instructions', 'dynamic-video-for-divi-posts' ); ?></h2> 119 <ol> 120 <li><?php esc_html_e( 'Edit a post and enter the video URL in the meta box on the right.', 'dynamic-video-for-divi-posts' ); ?></li> 121 <li><?php esc_html_e( 'In your Divi Builder template, add a Code or Text module and insert the shortcode: [dynamic_video]', 'dynamic-video-for-divi-posts' ); ?></li> 122 <li><?php esc_html_e( 'The video will be embedded automatically using WordPress’s oEmbed functionality.', 'dynamic-video-for-divi-posts' ); ?></li> 123 </ol> 124 </div> 125 <?php 129 ?> 130 <div class="wrap"> 131 <h1><?php esc_html_e( 'Dynamic Video for Divi Posts Details', 'dynamic-video-for-divi-posts' ); ?></h1> 132 <p><?php esc_html_e( 'This plugin dynamically embeds a video into your blog posts using a custom field. When editing a post, enter a video URL (e.g., a YouTube link) in the Video URL meta box, and then use the [dynamic_video] shortcode in your Divi Builder template to display the video.', 'dynamic-video-for-divi-posts' ); ?></p> 133 134 <form method="post" action="options.php"> 135 <?php 136 settings_fields( 'dynvid_settings_group' ); 137 do_settings_sections( 'dynvid_settings_group' ); 138 $use_featured_image = get_option( 'dynvid_use_featured_image', 'no' ); 139 ?> 140 <h2><?php esc_html_e( 'Settings', 'dynamic-video-for-divi-posts' ); ?></h2> 141 <table class="form-table"> 142 <tr> 143 <th scope="row"><?php esc_html_e( 'Use Featured Image Fallback', 'dynamic-video-for-divi-posts' ); ?></th> 144 <td> 145 <input type="checkbox" name="dynvid_use_featured_image" value="yes" <?php checked( $use_featured_image, 'yes' ); ?> /> 146 <?php esc_html_e( 'Display featured image when no video URL is provided', 'dynamic-video-for-divi-posts' ); ?> 147 </td> 148 </tr> 149 </table> 150 <?php submit_button(); ?> 151 </form> 152 153 <h2><?php esc_html_e( 'Usage Instructions', 'dynamic-video-for-divi-posts' ); ?></h2> 154 <ol> 155 <li><?php esc_html_e( 'Edit a post and enter the video URL in the meta box on the right.', 'dynamic-video-for-divi-posts' ); ?></li> 156 <li><?php esc_html_e( 'In your Divi Builder template, add a Code or Text module and insert the shortcode: [dynamic_video]', 'dynamic-video-for-divi-posts' ); ?></li> 157 <li><?php esc_html_e( 'The video will be embedded automatically using WordPress’s oEmbed functionality.', 'dynamic-video-for-divi-posts' ); ?></li> 158 <li><?php esc_html_e( 'If no video URL is provided and the featured image option is enabled, the post\'s featured image will be displayed instead.', 'dynamic-video-for-divi-posts' ); ?></li> 159 </ol> 160 </div> 161 <?php 126 162 } -
dynamic-video-for-divi-posts/trunk/readme.txt
r3261070 r3261851 1 1 === Dynamic Video for Divi Posts === 2 2 Contributors: hyperspective 3 Tags: video, dynamic, Divi, embed, shortcode 3 Tags: video, dynamic, Divi, embed, shortcode, featured image 4 4 Requires at least: 5.0 5 5 Tested up to: 6.7 6 Stable tag: 1.0. 16 Stable tag: 1.0.2 7 7 License: GPL2 8 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html 9 9 10 Short Description: Embeds videos into posts via a custom field and [dynamic_video] shortcode for Divi .10 Short Description: Embeds videos into posts via a custom field and [dynamic_video] shortcode for Divi, with optional featured image fallback. 11 11 12 12 == Description == 13 Dynamic Video for Divi Posts dynamically embeds a video into your blog posts by using a custom field. When editing a post, a new meta box labeled "Video URL" appears. Enter a video URL (e.g., a YouTube link) into this box, and then use the [dynamic_video] shortcode in your Divi Builder template. The video is automatically embedded using WordPress’s oEmbed functionality. 13 Dynamic Video for Divi Posts dynamically embeds a video into your blog posts by using a custom field. When editing a post, a new meta box labeled "Video URL" appears. Enter a video URL (e.g., a YouTube link) into this box, and then use the [dynamic_video] shortcode in your Divi Builder template. The video is automatically embedded using WordPress’s oEmbed functionality. New in version 1.0.2: Optional setting to display the post's featured image when no video URL is provided. 14 14 15 15 == Installation == … … 18 18 3. Edit any post to see the "Video URL" meta box and enter your video URL. 19 19 4. In your Divi Builder template, add a Code or Text module and insert the shortcode: `[dynamic_video]`. 20 5. (Optional) Go to Settings > Dynamic Video for Divi Posts to enable the featured image fallback option. 21 22 == Screenshots == 23 1. Settings, Instructions 24 2. Snippet example for Divi Code Module 25 3. Blog entry for video URL 20 26 21 27 == Frequently Asked Questions == … … 24 30 25 31 = Why isn’t my video appearing? = 26 Ensure that the video URL is correct and that your post type supports the shortcode. Also, verify that your Divi Builder template includes the `[dynamic_video]` shortcode. 32 Ensure that the video URL is correct and that your post type supports the shortcode. Also, verify that your Divi Builder template includes the `[dynamic_video]` shortcode. If no video appears and the featured image option is enabled, check if the post has a featured image set. 33 34 = How does the featured image fallback work? = 35 When enabled in the plugin settings, if no video URL is provided for a post, the plugin will display the post's featured image instead of leaving the space blank. You can turn this feature on or off in the plugin settings. 27 36 28 37 == Changelog == 38 = 1.0.2 = 39 * Added optional feature to display featured image when no video URL is provided 40 * Added settings page checkbox to enable/disable featured image fallback 41 * Updated documentation to include new feature instructions 42 29 43 = 1.0.1 = 30 44 * Renamed all functions, meta keys, nonce names, and admin slugs to use the unique prefix "dynvid_" to avoid naming conflicts. … … 35 49 36 50 == Upgrade Notice == 37 = 1.0. 1=38 This update updates function naming conventions and security practices to comply with WordPress coding standards. Please update to this version to continue using the plugin with enhanced security and compatibility.51 = 1.0.2 = 52 This update adds an optional featured image fallback feature when no video URL is provided, with a settings toggle. Update to access this new functionality while maintaining all previous features.
Note: See TracChangeset
for help on using the changeset viewer.