Changeset 3734621
- Timestamp:
- 10/08/2026 12:54:34 PM (2 weeks ago)
- Location:
- rotating-hero-image/trunk
- Files:
-
- 5 edited
-
README.txt (modified) (3 diffs)
-
admin/rotating-hero-image-admin.php (modified) (1 diff)
-
public/rotating-hero-image-public.php (modified) (1 diff)
-
rotating-hero-image.php (modified) (4 diffs)
-
uninstall.php (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
rotating-hero-image/trunk/README.txt
r2863129 r3734621 9 9 Author: Webstix 10 10 Requires at least: 5.4 11 Tested up to: 6.1.112 Stable tag: 1.0. 713 Version: 1.0. 411 Tested up to: 7.1 12 Stable tag: 1.0.8 13 Version: 1.0.8 14 14 License: GPL2 15 15 License URI: https://www.gnu.org/licenses/gpl-2.0.html 16 17 Automatically rotate multiple hero banner images on a schedule — no slideshow bloat, just fast, clean image rotation. 16 18 17 19 == Description == … … 86 88 * Initial Release -- February 2022 87 89 88 89 90 = 1.0.1 = 90 91 * Setting link added in plugin page. … … 107 108 = 1.0.7 = 108 109 * Updated the plugin to be compatible with 6.1.1 110 111 = 1.0.8 = 112 * Security hardening: fixed nonce verification, sanitization, escaping 113 * Fixed deprecated functions: register_setting() callback, date() → wp_date(), tax_query field 114 * Fixed naming conventions and prefixing for WordPress standards 115 * Updated tested up to WordPress 6.7 -
rotating-hero-image/trunk/admin/rotating-hero-image-admin.php
r2700972 r3734621 8 8 * @since 1.0.0 9 9 */ 10 10 11 // If this file is called directly, abort. 11 12 if ( ! defined( 'WPINC' ) ) { 12 die; 13 } 14 class rotating_hero_image{ 15 function __construct() { 16 // Action to add script at front side 17 add_action( 'admin_enqueue_scripts', 'wsxhmi_EnqueueCustomAdminStyle',99 ); 18 //Action to add Post type 19 add_action( 'init', 'wsxhi_HeroImagePostType' ); 20 //Action to add meta boxes 21 add_action( 'add_meta_boxes', 'wsxhi_AddButtonFieldsMetabox' ); 22 //Action to save metabox data 23 add_action('save_post', 'wsxhi_build_a_meta_box_button_fields_save',99); 24 //Action to add setting submenu 25 add_action( 'admin_menu', 'wsxhi_add_settings_submenu' ); 26 //Action to add register settings 27 add_action( 'admin_init', 'wsxhi_RegisterSettings' ); 28 //Action to add category shortcode 29 add_action( 'admin_init', 'wsxhi_category_add_dynamic_hooks' ); 30 //Action to add categories fields 31 add_action( 'wsxhi_categories_edit_form_fields','wsxhi_taxonomy_edit_custom_meta_field', 10, 2 ); 32 } 33 } 34 /** 35 * Admin custom stylesheet. 36 */ 37 function wsxhmi_EnqueueCustomAdminStyle() { 13 die; 14 } 15 16 /** 17 * Main admin class for the Rotating Hero Image plugin. 18 * 19 * Renamed from rotating_hero_image to RHI_Rotating_Hero_Image to satisfy 20 * WordPress naming conventions (NonPrefixedClassFound rule). 21 * 22 * @since 1.0.0 23 */ 24 class RHI_Rotating_Hero_Image { 25 26 /** 27 * Constructor – registers all admin hooks. 28 */ 29 public function __construct() { 30 // Enqueue admin scripts and styles. 31 add_action( 'admin_enqueue_scripts', 'RHI_enqueue_admin_assets', 99 ); 32 // Register hero_image custom post type and taxonomy. 33 add_action( 'init', 'RHI_register_hero_post_type' ); 34 // Add meta boxes to the hero_image edit screen. 35 add_action( 'add_meta_boxes', 'RHI_add_button_metabox' ); 36 // Save meta box data on post save. 37 add_action( 'save_post', 'RHI_save_button_metabox', 99 ); 38 // Add the Settings submenu under Hero Image CPT. 39 add_action( 'admin_menu', 'RHI_add_settings_submenu' ); 40 // Register plugin settings with the Settings API. 41 add_action( 'admin_init', 'RHI_register_settings' ); 42 // Register dynamic taxonomy column hooks. 43 add_action( 'admin_init', 'RHI_category_column_hooks' ); 44 // Render extra fields on the category edit form. 45 add_action( 'wsxhi_categories_edit_form_fields', 'RHI_taxonomy_edit_shortcode_field', 10, 2 ); 46 } 47 } 48 49 /** 50 * Enqueue admin stylesheet and script. 51 */ 52 function RHI_enqueue_admin_assets() { 38 53 wp_enqueue_style( 'wp-color-picker' ); 39 wp_enqueue_style( 'custom_wsxhi_wp_admin', plugin_dir_url( __FILE__ ). 'css/admin.css', false, '1.0.0' ); 40 wp_enqueue_script('custom_wsxhi_wp_admin_js', plugin_dir_url( __FILE__ ).'js/admin.js', array( 'jquery','wp-color-picker' )) ; 41 } 42 /** 43 * Create hero_image custom post type 44 */ 45 function wsxhi_HeroImagePostType() { 46 register_post_type( 'hero_image', 47 array( 48 'labels' => array( 49 'name' => __( 'Hero Image', '' ), 50 'singular_name' => __( 'Hero Image', '' ), 51 'add_new' => __( 'Add New', 'textdomain' ), 52 'add_new_item' => __( 'Add New Hero Image', 'textdomain' ), 53 'new_item' => __( 'New Hero Image', 'textdomain' ), 54 'edit_item' => __( 'Edit Hero Image', 'textdomain' ), 55 'view_item' => __( 'View Hero Image', 'textdomain' ), 56 'all_items' => __( 'All Hero Images', 'textdomain' ), 57 ), 58 'has_archive' => true, 59 'hierarchical' => true, 60 'menu_icon' => 'dashicons-format-gallery', 61 'public' => true, 62 'rewrite' => array( 'slug' => 'hero_image', 'with_front' => false ), 63 'supports' => array( 'title', 'author','editor', 'thumbnail' ), 64 'taxonomies' => array( 'wsxhi_categories' ), 65 ) 66 ); 67 register_taxonomy( 'wsxhi_categories', 'hero_image', 68 array( 69 'labels' => array( 70 'name' => _x( 'Categories', 'taxonomy general name', '' ), 71 'add_new_item' => __( 'Add Category', '' ), 72 'new_item_name' => __( 'New Category', '' ), 73 ), 74 'exclude_from_search' => true, 75 'has_archive' => true, 76 'hierarchical' => true, 77 'rewrite' => array( 'slug' => 'hero_image', 'with_front' => false ), 78 'show_ui' => true, 54 wp_enqueue_style( 55 'rhi_admin_css', 56 plugin_dir_url( __FILE__ ) . 'css/admin.css', 57 array(), 58 RHI_PLUGIN_VERSION 59 ); 60 wp_enqueue_script( 61 'rhi_admin_js', 62 plugin_dir_url( __FILE__ ) . 'js/admin.js', 63 array( 'jquery', 'wp-color-picker' ), 64 RHI_PLUGIN_VERSION, 65 true 66 ); 67 } 68 69 /** 70 * Register the hero_image custom post type and wsxhi_categories taxonomy. 71 */ 72 function RHI_register_hero_post_type() { 73 register_post_type( 74 'hero_image', 75 array( 76 'labels' => array( 77 'name' => __( 'Hero Image', 'rotating-hero-image' ), 78 'singular_name' => __( 'Hero Image', 'rotating-hero-image' ), 79 'add_new' => __( 'Add New', 'rotating-hero-image' ), 80 'add_new_item' => __( 'Add New Hero Image', 'rotating-hero-image' ), 81 'new_item' => __( 'New Hero Image', 'rotating-hero-image' ), 82 'edit_item' => __( 'Edit Hero Image', 'rotating-hero-image' ), 83 'view_item' => __( 'View Hero Image', 'rotating-hero-image' ), 84 'all_items' => __( 'All Hero Images', 'rotating-hero-image' ), 85 ), 86 'has_archive' => true, 87 'hierarchical' => true, 88 'menu_icon' => 'dashicons-format-gallery', 89 'public' => true, 90 'rewrite' => array( 'slug' => 'hero_image', 'with_front' => false ), 91 'supports' => array( 'title', 'author', 'editor', 'thumbnail' ), 92 'taxonomies' => array( 'wsxhi_categories' ), 93 ) 94 ); 95 96 register_taxonomy( 97 'wsxhi_categories', 98 'hero_image', 99 array( 100 'labels' => array( 101 'name' => _x( 'Categories', 'taxonomy general name', 'rotating-hero-image' ), 102 'add_new_item' => __( 'Add Category', 'rotating-hero-image' ), 103 'new_item_name' => __( 'New Category', 'rotating-hero-image' ), 104 ), 105 'exclude_from_search' => true, 106 'has_archive' => true, 107 'hierarchical' => true, 108 'rewrite' => array( 'slug' => 'hero_image', 'with_front' => false ), 109 'show_ui' => true, 79 110 'show_tagcloud' => false, 80 'show_admin_column' => true 81 ) 82 ); 83 } 84 /** 85 * Adding Meta boxes 86 */ 87 function wsxhi_AddButtonFieldsMetabox() { 88 global $post; 89 add_meta_box( 'button-fields', 'Button Settings', 'wsxhi_button_filters_meta_box_display', 'hero_image', 'normal', 'high'); 90 } 91 /** 92 * Adding Meta boxes input field 93 */ 94 function wsxhi_button_filters_meta_box_display() { 95 global $post; 96 $button_text = get_post_meta($post->ID, 'button_text', true); 97 $button_link = get_post_meta($post->ID, 'button_link', true); 98 $link_type = get_post_meta($post->ID, 'link_type', true); 99 wp_nonce_field( 'button_fields_meta_box_nonce', 'button_fields_meta_box_nonce' ); 100 ?> 101 <table id="wsxhi-build-button-fieldset widefat" width="100%"> 102 <tbody> 103 <tr> 104 <td class="clsLabel">Button Text:</td> 105 <td><input type="text" name="button_text" value="<?php if(!empty($button_text)) echo esc_attr($button_text); ?>" /></td> 106 </tr> 107 <tr class="clsLabel"> 108 <td class="clsLabel"><label for="wsxsml_icon"> Link Type: </label></td> 109 <td> 110 <label><input type="radio" class="link_type" name="link_type" value="clsInternal" <?php if($link_type == 'clsInternal') echo 'checked'; ?>>Internal</label> 111 <label><input type="radio" class="link_type" name="link_type" value="clsExternal" <?php if($link_type == 'clsExternal') echo 'checked'; ?>>External</label> 112 </td> 113 </tr> 114 <tr> 115 <td class="clsLabel">Button Link:</td> 116 <td><input type="text" name="button_link" value="<?php if($button_link != '') echo esc_url( $button_link ); ?>" /></td> 117 </tr> 118 </tbody> 119 </table> 120 <?php 121 } 122 /** 123 * Save Meta boxes values 124 */ 125 function wsxhi_build_a_meta_box_button_fields_save($post_id) { 126 if ( ! isset( $_POST['button_fields_meta_box_nonce'] ) || 127 ! wp_verify_nonce( $_POST['button_fields_meta_box_nonce'], 'button_fields_meta_box_nonce' ) ) 128 return; 129 if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) 130 return; 131 if (!current_user_can('edit_post', $post_id)) 132 return; 133 $button_text = sanitize_text_field($_POST['button_text']); 134 $button_link = sanitize_text_field($_POST['button_link']); 135 $link_type = sanitize_text_field($_POST['link_type']); 136 update_post_meta( $post_id, 'button_text', $button_text ); 137 update_post_meta( $post_id, 'button_link', $button_link ); 138 update_post_meta( $post_id, 'link_type', $link_type ); 139 } 140 /** 141 * Adding settings submenu 142 */ 143 function wsxhi_add_settings_submenu() { 111 'show_admin_column' => true, 112 ) 113 ); 114 } 115 116 /** 117 * Register the Button Settings meta box. 118 */ 119 function RHI_add_button_metabox() { 120 add_meta_box( 121 'rhi-button-fields', 122 esc_html__( 'Button Settings', 'rotating-hero-image' ), 123 'RHI_render_button_metabox', 124 'hero_image', 125 'normal', 126 'high' 127 ); 128 } 129 130 /** 131 * Render Button Settings meta box fields. 132 */ 133 function RHI_render_button_metabox() { 134 global $post; 135 $rhi_button_text = get_post_meta( $post->ID, 'button_text', true ); 136 $rhi_button_link = get_post_meta( $post->ID, 'button_link', true ); 137 $rhi_link_type = get_post_meta( $post->ID, 'link_type', true ); 138 wp_nonce_field( 'rhi_button_metabox_nonce', 'rhi_button_metabox_nonce' ); 139 ?> 140 <table id="rhi-button-fieldset" class="widefat" width="100%"> 141 <tbody> 142 <tr> 143 <td class="clsLabel"><?php esc_html_e( 'Button Text:', 'rotating-hero-image' ); ?></td> 144 <td><input type="text" name="button_text" value="<?php echo esc_attr( $rhi_button_text ); ?>" /></td> 145 </tr> 146 <tr class="clsLabel"> 147 <td class="clsLabel"> 148 <label for="rhi-link-type"><?php esc_html_e( 'Link Type:', 'rotating-hero-image' ); ?></label> 149 </td> 150 <td> 151 <label> 152 <input type="radio" id="rhi-link-type" class="link_type" name="link_type" value="clsInternal" <?php checked( $rhi_link_type, 'clsInternal' ); ?>> 153 <?php esc_html_e( 'Internal', 'rotating-hero-image' ); ?> 154 </label> 155 <label> 156 <input type="radio" class="link_type" name="link_type" value="clsExternal" <?php checked( $rhi_link_type, 'clsExternal' ); ?>> 157 <?php esc_html_e( 'External', 'rotating-hero-image' ); ?> 158 </label> 159 </td> 160 </tr> 161 <tr> 162 <td class="clsLabel"><?php esc_html_e( 'Button Link:', 'rotating-hero-image' ); ?></td> 163 <td><input type="text" name="button_link" value="<?php echo esc_url( $rhi_button_link ); ?>" /></td> 164 </tr> 165 </tbody> 166 </table> 167 <?php 168 } 169 170 /** 171 * Save Button Settings meta box values. 172 * 173 * @param int $post_id Post ID being saved. 174 */ 175 function RHI_save_button_metabox( $post_id ) { 176 // Verify nonce. 177 if ( ! isset( $_POST['rhi_button_metabox_nonce'] ) || 178 ! wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['rhi_button_metabox_nonce'] ) ), 'rhi_button_metabox_nonce' ) ) { 179 return; 180 } 181 182 // Skip autosave. 183 if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { 184 return; 185 } 186 187 // Check user capability. 188 if ( ! current_user_can( 'edit_post', $post_id ) ) { 189 return; 190 } 191 192 // Sanitize and persist meta. 193 $rhi_button_text = isset( $_POST['button_text'] ) ? sanitize_text_field( wp_unslash( $_POST['button_text'] ) ) : ''; 194 $rhi_button_link = isset( $_POST['button_link'] ) ? esc_url_raw( wp_unslash( $_POST['button_link'] ) ) : ''; 195 $rhi_link_type = isset( $_POST['link_type'] ) ? sanitize_text_field( wp_unslash( $_POST['link_type'] ) ) : ''; 196 197 update_post_meta( $post_id, 'button_text', $rhi_button_text ); 198 update_post_meta( $post_id, 'button_link', $rhi_button_link ); 199 update_post_meta( $post_id, 'link_type', $rhi_link_type ); 200 } 201 202 /** 203 * Add Settings submenu page under Hero Image CPT. 204 */ 205 function RHI_add_settings_submenu() { 144 206 add_submenu_page( 145 207 'edit.php?post_type=hero_image', 146 __( 'Settings', ' menu-test' ),147 __( 'Settings', ' menu-test' ),208 __( 'Settings', 'rotating-hero-image' ), 209 __( 'Settings', 'rotating-hero-image' ), 148 210 'manage_options', 149 211 'options', 150 'wsxhi_options_page' 151 ); 152 } 153 /** 154 * Register all the setting options 155 */ 156 function wsxhi_RegisterSettings() { 157 158 add_option( 'rhi_show_banner_title', 'Yes'); 159 add_option( 'rhi_show_banner_text', 'Yes'); 160 add_option( 'rhi_show_banner_button', 'Yes'); 161 add_option( 'rhi_width', '100'); 162 add_option( 'rhi_height', '300'); 163 add_option( 'rhi_opacity', '0.5'); 164 add_option( 'rhi_title_font_style', 'h1'); 165 add_option( 'rhi_banner_text_font_style', 'p'); 166 add_option( 'rhi_button_color', ''); 167 add_option( 'rhi_button_text_color', ''); 168 add_option( 'rhi_title_font_color', ''); 169 add_option( 'rhi_banner_text_font_color', ''); 170 add_option( 'rhi_time_interval', '1'); 171 add_option( 'rhi_banner_text_align', 'left'); 172 register_setting( 'wsxhi_options_group', 'rhi_show_banner_title', 'myplugin_callback' ); 173 register_setting( 'wsxhi_options_group', 'rhi_show_banner_text', 'myplugin_callback' ); 174 register_setting( 'wsxhi_options_group', 'rhi_show_banner_button', 'myplugin_callback' ); 175 register_setting( 'wsxhi_options_group', 'rhi_width', 'myplugin_callback' ); 176 register_setting( 'wsxhi_options_group', 'rhi_height', 'myplugin_callback' ); 177 register_setting( 'wsxhi_options_group', 'rhi_opacity', 'myplugin_callback' ); 178 register_setting( 'wsxhi_options_group', 'rhi_title_font_style', 'myplugin_callback' ); 179 register_setting( 'wsxhi_options_group', 'rhi_banner_text_font_style', 'myplugin_callback' ); 180 register_setting( 'wsxhi_options_group', 'rhi_button_color', 'myplugin_callback' ); 181 register_setting( 'wsxhi_options_group', 'rhi_button_text_color', 'myplugin_callback' ); 182 register_setting( 'wsxhi_options_group', 'rhi_title_font_color', 'myplugin_callback' ); 183 register_setting( 'wsxhi_options_group', 'rhi_banner_text_font_color', 'myplugin_callback' ); 184 register_setting( 'wsxhi_options_group', 'rhi_time_interval', 'myplugin_callback' ); 185 register_setting( 'wsxhi_options_group', 'rhi_banner_text_align', 'myplugin_callback' ); 186 187 } 188 /** 189 * Display all the setting options 190 */ 191 function wsxhi_options_page() { 192 if( isset($_GET['settings-updated']) ) { 193 ?> 194 <div id="message" class="updated"> 195 <p><strong><?php _e('Settings saved.') ?></strong></p> 212 'RHI_render_options_page' 213 ); 214 } 215 216 /** 217 * Register all plugin settings via the Settings API. 218 * 219 * Using array-format sanitize_callback (string callback deprecated since WP 4.7). 220 */ 221 function RHI_register_settings() { 222 add_option( 'rhi_show_banner_title', 'Yes' ); 223 add_option( 'rhi_show_banner_text', 'Yes' ); 224 add_option( 'rhi_show_banner_button', 'Yes' ); 225 add_option( 'rhi_width', '100' ); 226 add_option( 'rhi_height', '300' ); 227 add_option( 'rhi_opacity', '0.5' ); 228 add_option( 'rhi_title_font_style', 'h1' ); 229 add_option( 'rhi_banner_text_font_style', 'p' ); 230 add_option( 'rhi_button_color', '' ); 231 add_option( 'rhi_button_text_color', '' ); 232 add_option( 'rhi_title_font_color', '' ); 233 add_option( 'rhi_banner_text_font_color', '' ); 234 add_option( 'rhi_time_interval', '1' ); 235 add_option( 'rhi_banner_text_align', 'left' ); 236 237 $rhi_text_cb = array( 'sanitize_callback' => 'sanitize_text_field' ); 238 $rhi_color_cb = array( 'sanitize_callback' => 'sanitize_hex_color' ); 239 $rhi_int_cb = array( 'sanitize_callback' => 'absint' ); 240 $rhi_float_cb = array( 'sanitize_callback' => 'floatval' ); 241 242 register_setting( 'rhi_options_group', 'rhi_show_banner_title', $rhi_text_cb ); 243 register_setting( 'rhi_options_group', 'rhi_show_banner_text', $rhi_text_cb ); 244 register_setting( 'rhi_options_group', 'rhi_show_banner_button', $rhi_text_cb ); 245 register_setting( 'rhi_options_group', 'rhi_width', $rhi_int_cb ); 246 register_setting( 'rhi_options_group', 'rhi_height', $rhi_int_cb ); 247 register_setting( 'rhi_options_group', 'rhi_opacity', $rhi_float_cb ); 248 register_setting( 'rhi_options_group', 'rhi_title_font_style', $rhi_text_cb ); 249 register_setting( 'rhi_options_group', 'rhi_banner_text_font_style', $rhi_text_cb ); 250 register_setting( 'rhi_options_group', 'rhi_button_color', $rhi_color_cb ); 251 register_setting( 'rhi_options_group', 'rhi_button_text_color', $rhi_color_cb ); 252 register_setting( 'rhi_options_group', 'rhi_title_font_color', $rhi_color_cb ); 253 register_setting( 'rhi_options_group', 'rhi_banner_text_font_color', $rhi_color_cb ); 254 register_setting( 'rhi_options_group', 'rhi_time_interval', $rhi_int_cb ); 255 register_setting( 'rhi_options_group', 'rhi_banner_text_align', $rhi_text_cb ); 256 } 257 258 /** 259 * Render the plugin settings page. 260 * 261 * The settings-updated flag is set by WordPress core after a successful 262 * options.php form submission; nonce is already verified by WP core at that point. 263 */ 264 function RHI_render_options_page() { 265 // WordPress core verifies the nonce during options.php processing. 266 // We only display a notice here based on the resulting redirect parameter. 267 // phpcs:ignore WordPress.Security.NonceVerification.Recommended 268 if ( isset( $_GET['settings-updated'] ) ) { 269 ?> 270 <div id="rhi-settings-notice" class="updated notice is-dismissible"> 271 <p><strong><?php esc_html_e( 'Settings saved.', 'rotating-hero-image' ); ?></strong></p> 196 272 </div> 197 <?php } ?> 198 <h2>Image Settings:</h2> 273 <?php 274 } 275 ?> 276 <h2><?php esc_html_e( 'Image Settings:', 'rotating-hero-image' ); ?></h2> 199 277 <form method="post" action="options.php"> 200 <?php settings_fields( ' wsxhi_options_group' ); ?>278 <?php settings_fields( 'rhi_options_group' ); ?> 201 279 <div class="clsHerImageOptions"> 202 <table> 203 <tr> 204 <th><label for="rhi_width">Width: </label></th> 205 <td><input type="number" id="rhi_width" name="rhi_width" minlength="2" maxlength="3" min="1" max="100" value="<?php if(!empty(get_option('rhi_width'))) echo esc_attr(get_option('rhi_width')); ?>" required/> %</td> 206 </tr> 207 <tr> 208 <th><label for="width">Height: </label></th> 209 <td><input type="number" id="rhi_height" name="rhi_height" minlength="1" min="1" value="<?php if(!empty(get_option('rhi_height'))) echo esc_attr(get_option('rhi_height')); ?>" required /> px</td> 210 </tr> 211 <tr> 212 <th><label for="width">Opacity: </label></th> 213 <td><input type="number" id="rhi_opacity" name="rhi_opacity" minlength="1" min="0" max="1" step="0.1" value="<?php if(!empty(get_option('rhi_opacity'))) echo esc_attr(get_option('rhi_opacity')); ?>" required/></td> 280 <table> 281 <tr> 282 <th><label for="rhi_width"><?php esc_html_e( 'Width:', 'rotating-hero-image' ); ?></label></th> 283 <td> 284 <input type="number" id="rhi_width" name="rhi_width" 285 min="1" max="100" 286 value="<?php echo esc_attr( get_option( 'rhi_width' ) ); ?>" 287 required /> 288 % 289 </td> 290 </tr> 291 <tr> 292 <th><label for="rhi_height"><?php esc_html_e( 'Height:', 'rotating-hero-image' ); ?></label></th> 293 <td> 294 <input type="number" id="rhi_height" name="rhi_height" 295 min="1" 296 value="<?php echo esc_attr( get_option( 'rhi_height' ) ); ?>" 297 required /> 298 px 299 </td> 300 </tr> 301 <tr> 302 <th><label for="rhi_opacity"><?php esc_html_e( 'Opacity:', 'rotating-hero-image' ); ?></label></th> 303 <td> 304 <input type="number" id="rhi_opacity" name="rhi_opacity" 305 min="0" max="1" step="0.1" 306 value="<?php echo esc_attr( get_option( 'rhi_opacity' ) ); ?>" 307 required /> 308 </td> 214 309 </tr> 215 310 </table> 216 <h2>Banner Text Settings:</h2> 311 312 <h2><?php esc_html_e( 'Banner Text Settings:', 'rotating-hero-image' ); ?></h2> 217 313 <table> 218 314 <tr> 219 <th><label for="wsxsml_icon">Show Banner Title:</label></th>220 <td> 221 <label><input type="radio" name="rhi_show_banner_title" value="Yes" <?php if(get_option('rhi_show_banner_title')== 'Yes') echo 'checked'; ?>>Yes</label>222 <label><input type="radio" name="rhi_show_banner_title" value="No" <?php if(get_option('rhi_show_banner_title')== 'No') echo 'checked'; ?>> No</label>223 </td> 224 </tr> 225 <tr> 226 <th><label for="wsxsml_icon">Show Banner Text:</label></th>227 <td> 228 <label><input type="radio" name="rhi_show_banner_text" value="Yes" <?php if(get_option('rhi_show_banner_text')== 'Yes') echo 'checked'; ?>>Yes</label>229 <label><input type="radio" name="rhi_show_banner_text" value="No" <?php if(get_option('rhi_show_banner_text')== 'No') echo 'checked'; ?>> No</label>230 </td> 231 </tr> 232 <tr> 233 <th><label for="wsxsml_icon">Show Banner Button:</label></th>234 <td> 235 <label><input type="radio" name="rhi_show_banner_button" value="Yes" <?php if(get_option('rhi_show_banner_button')== 'Yes') echo 'checked'; ?>>Yes</label>236 <label><input type="radio" name="rhi_show_banner_button" value="No" <?php if(get_option('rhi_show_banner_button')== 'No') echo 'checked'; ?>> No</label>237 </td> 238 </tr> 239 <tr> 240 <th><label for="wsxsml_icon">Title Font Style:</label></th>241 <td> 242 <label><input type="radio" name="rhi_title_font_style" value="h1" <?php if(get_option('rhi_title_font_style')== 'h1') echo 'checked'; ?>>H1</label>243 <label><input type="radio" name="rhi_title_font_style" value="h2" <?php if(get_option('rhi_title_font_style')== 'h2') echo 'checked'; ?>>H2</label>244 <label><input type="radio" name="rhi_title_font_style" value="h3" <?php if(get_option('rhi_title_font_style')== 'h3') echo 'checked'; ?>>H3</label>245 </td> 246 </tr> 247 <tr> 248 <th><label for="wsxsml_icon">Text Font Style:</label></th>249 <td> 250 <label><input type="radio" name="rhi_banner_text_font_style" value="p" <?php if(get_option('rhi_banner_text_font_style')== 'p') echo 'checked'; ?>>p</label>251 <label><input type="radio" name="rhi_banner_text_font_style" value="span" <?php if(get_option('rhi_banner_text_font_style')== 'span') echo 'checked'; ?>>span</label>252 <label><input type="radio" name="rhi_banner_text_font_style" value="h3" <?php if(get_option('rhi_banner_text_font_style')== 'h3') echo 'checked'; ?>>h3</label>253 </td> 254 </tr> 255 <tr> 256 <th><label for="wsxsml_icon">Text Align:</label></th>257 <td> 258 <label><input type="radio" name="rhi_banner_text_align" value="left" <?php if(get_option('rhi_banner_text_align')== 'left') echo 'checked'; ?>>Left</label>259 <label><input type="radio" name="rhi_banner_text_align" value="center" <?php if(get_option('rhi_banner_text_align')== 'center') echo 'checked'; ?>>Center</label>260 <label><input type="radio" name="rhi_banner_text_align" value="right" <?php if(get_option('rhi_banner_text_align')== 'right') echo 'checked'; ?>>Right</label>315 <th><label><?php esc_html_e( 'Show Banner Title:', 'rotating-hero-image' ); ?></label></th> 316 <td> 317 <label><input type="radio" name="rhi_show_banner_title" value="Yes" <?php checked( get_option( 'rhi_show_banner_title' ), 'Yes' ); ?>><?php esc_html_e( 'Yes', 'rotating-hero-image' ); ?></label> 318 <label><input type="radio" name="rhi_show_banner_title" value="No" <?php checked( get_option( 'rhi_show_banner_title' ), 'No' ); ?>><?php esc_html_e( 'No', 'rotating-hero-image' ); ?></label> 319 </td> 320 </tr> 321 <tr> 322 <th><label><?php esc_html_e( 'Show Banner Text:', 'rotating-hero-image' ); ?></label></th> 323 <td> 324 <label><input type="radio" name="rhi_show_banner_text" value="Yes" <?php checked( get_option( 'rhi_show_banner_text' ), 'Yes' ); ?>><?php esc_html_e( 'Yes', 'rotating-hero-image' ); ?></label> 325 <label><input type="radio" name="rhi_show_banner_text" value="No" <?php checked( get_option( 'rhi_show_banner_text' ), 'No' ); ?>><?php esc_html_e( 'No', 'rotating-hero-image' ); ?></label> 326 </td> 327 </tr> 328 <tr> 329 <th><label><?php esc_html_e( 'Show Banner Button:', 'rotating-hero-image' ); ?></label></th> 330 <td> 331 <label><input type="radio" name="rhi_show_banner_button" value="Yes" <?php checked( get_option( 'rhi_show_banner_button' ), 'Yes' ); ?>><?php esc_html_e( 'Yes', 'rotating-hero-image' ); ?></label> 332 <label><input type="radio" name="rhi_show_banner_button" value="No" <?php checked( get_option( 'rhi_show_banner_button' ), 'No' ); ?>><?php esc_html_e( 'No', 'rotating-hero-image' ); ?></label> 333 </td> 334 </tr> 335 <tr> 336 <th><label><?php esc_html_e( 'Title Font Style:', 'rotating-hero-image' ); ?></label></th> 337 <td> 338 <label><input type="radio" name="rhi_title_font_style" value="h1" <?php checked( get_option( 'rhi_title_font_style' ), 'h1' ); ?>>H1</label> 339 <label><input type="radio" name="rhi_title_font_style" value="h2" <?php checked( get_option( 'rhi_title_font_style' ), 'h2' ); ?>>H2</label> 340 <label><input type="radio" name="rhi_title_font_style" value="h3" <?php checked( get_option( 'rhi_title_font_style' ), 'h3' ); ?>>H3</label> 341 </td> 342 </tr> 343 <tr> 344 <th><label><?php esc_html_e( 'Text Font Style:', 'rotating-hero-image' ); ?></label></th> 345 <td> 346 <label><input type="radio" name="rhi_banner_text_font_style" value="p" <?php checked( get_option( 'rhi_banner_text_font_style' ), 'p' ); ?>>p</label> 347 <label><input type="radio" name="rhi_banner_text_font_style" value="span" <?php checked( get_option( 'rhi_banner_text_font_style' ), 'span' ); ?>>span</label> 348 <label><input type="radio" name="rhi_banner_text_font_style" value="h3" <?php checked( get_option( 'rhi_banner_text_font_style' ), 'h3' ); ?>>h3</label> 349 </td> 350 </tr> 351 <tr> 352 <th><label><?php esc_html_e( 'Text Align:', 'rotating-hero-image' ); ?></label></th> 353 <td> 354 <label><input type="radio" name="rhi_banner_text_align" value="left" <?php checked( get_option( 'rhi_banner_text_align' ), 'left' ); ?>><?php esc_html_e( 'Left', 'rotating-hero-image' ); ?></label> 355 <label><input type="radio" name="rhi_banner_text_align" value="center" <?php checked( get_option( 'rhi_banner_text_align' ), 'center' ); ?>><?php esc_html_e( 'Center', 'rotating-hero-image' ); ?></label> 356 <label><input type="radio" name="rhi_banner_text_align" value="right" <?php checked( get_option( 'rhi_banner_text_align' ), 'right' ); ?>><?php esc_html_e( 'Right', 'rotating-hero-image' ); ?></label> 261 357 </td> 262 358 </tr> 263 359 </table> 264 <h2>Color Settings:</h2> 360 361 <h2><?php esc_html_e( 'Color Settings:', 'rotating-hero-image' ); ?></h2> 265 362 <table> 266 363 <tr> 267 <th><label for=" button-color">Button Color:</label></th>268 <td><input type="text" id=" button-color" name="rhi_button_color" value="<?php if(!empty(get_option('rhi_button_color'))) echo esc_attr(get_option('rhi_button_color')); ?>" class="button-color-picker"/></td>269 </tr> 270 <tr> 271 <th><label for=" button-color">Button Text Color:</label></th>272 <td><input type="text" id=" button-color" name="rhi_button_text_color" value="<?php if(!empty(get_option('rhi_button_text_color'))) echo esc_attr(get_option('rhi_button_text_color')); ?>" class="button-text-color-picker"/></td>273 </tr> 274 <tr> 275 <th><label for=" button-color">Title Font Color:</label></th>276 <td><input type="text" id=" button-color" name="rhi_title_font_color" value="<?php if(!empty(get_option('rhi_title_font_color'))) echo esc_attr(get_option('rhi_title_font_color')); ?>" class="title-font-color-picker"/></td>277 </tr> 278 <tr> 279 <th><label for=" button-color">Text font color:</label></th>280 <td><input type="text" id=" button-color" name="rhi_banner_text_font_color" value="<?php if(!empty(get_option('rhi_banner_text_font_color'))) echo esc_attr(get_option('rhi_banner_text_font_color')); ?>" class="banner-text-font-color-picker"/></td>364 <th><label for="rhi-button-color"><?php esc_html_e( 'Button Color:', 'rotating-hero-image' ); ?></label></th> 365 <td><input type="text" id="rhi-button-color" name="rhi_button_color" value="<?php echo esc_attr( get_option( 'rhi_button_color' ) ); ?>" class="button-color-picker" /></td> 366 </tr> 367 <tr> 368 <th><label for="rhi-button-text-color"><?php esc_html_e( 'Button Text Color:', 'rotating-hero-image' ); ?></label></th> 369 <td><input type="text" id="rhi-button-text-color" name="rhi_button_text_color" value="<?php echo esc_attr( get_option( 'rhi_button_text_color' ) ); ?>" class="button-text-color-picker" /></td> 370 </tr> 371 <tr> 372 <th><label for="rhi-title-font-color"><?php esc_html_e( 'Title Font Color:', 'rotating-hero-image' ); ?></label></th> 373 <td><input type="text" id="rhi-title-font-color" name="rhi_title_font_color" value="<?php echo esc_attr( get_option( 'rhi_title_font_color' ) ); ?>" class="title-font-color-picker" /></td> 374 </tr> 375 <tr> 376 <th><label for="rhi-text-font-color"><?php esc_html_e( 'Text Font Color:', 'rotating-hero-image' ); ?></label></th> 377 <td><input type="text" id="rhi-text-font-color" name="rhi_banner_text_font_color" value="<?php echo esc_attr( get_option( 'rhi_banner_text_font_color' ) ); ?>" class="banner-text-font-color-picker" /></td> 281 378 </tr> 282 379 </table> 283 <h2>Hero Image Settings:</h2> 380 381 <h2><?php esc_html_e( 'Hero Image Settings:', 'rotating-hero-image' ); ?></h2> 284 382 <table> 285 383 <tr> 286 <th><label for="wsxsml_icon">Time Interval: </label></th> 287 <td> 288 <input type="number" id="rhi_time_interval" name="rhi_time_interval" minlength="1" maxlength="2" min="1" max="24" value="<?php if(!empty(get_option('rhi_time_interval'))) echo esc_attr(get_option('rhi_time_interval')); ?>" class="rhi_time_interval" required/> Hr(s) 289 </td> 290 </tr> 291 </table> 292 293 <?php submit_button(); ?> 384 <th><label for="rhi_time_interval"><?php esc_html_e( 'Time Interval:', 'rotating-hero-image' ); ?></label></th> 385 <td> 386 <input type="number" id="rhi_time_interval" name="rhi_time_interval" 387 min="1" max="24" 388 value="<?php echo esc_attr( get_option( 'rhi_time_interval' ) ); ?>" 389 class="rhi_time_interval" required /> 390 <?php esc_html_e( 'Hr(s)', 'rotating-hero-image' ); ?> 391 </td> 392 </tr> 393 </table> 394 <?php submit_button(); ?> 294 395 </div> 295 396 </form> 296 397 <?php 297 398 } 298 /** 299 * Register all the column 300 */ 301 function wsxhi_category_add_dynamic_hooks() { 302 $taxonomy = 'wsxhi_categories'; 303 add_filter( 'manage_' . $taxonomy . '_custom_column', 'wsxhi_category_taxonomy_rows',15, 3 ); 304 add_filter( 'manage_edit-' . $taxonomy . '_columns', 'wsxhi_category_taxonomy_columns' ); 305 } 306 /** 307 * Add category shortcode column 308 */ 309 function wsxhi_category_taxonomy_columns( $original_columns ) { 310 $new_columns = $original_columns; 311 array_splice( $new_columns, 1 ); 312 $new_columns['wsxhi_shortcode'] = esc_html__( 'Shortcode', 'taxonomy-images' ); 313 unset($original_columns['name']); 314 unset($original_columns['description']); 315 unset($original_columns['slug']); 316 unset($original_columns['short_code']); 317 unset($original_columns['posts']); 318 return array_merge ( $original_columns, array ( 319 'name' => __ ('Name'), 320 'wsxhi_shortcode' => __ ( 'Shortcode' ), 321 'slug' => __ ( 'Slug' ), 322 'posts' => __('Count') 323 ) ); 324 } 325 /** 326 * Display shortcode column in category list page 327 */ 328 function wsxhi_category_taxonomy_rows( $row, $column_name, $term_id ) { 329 $t_id = $term_id; 330 if ( 'wsxhi_shortcode' === $column_name ) { 331 return '<input type="text" value="[wsx_hero_image catid='.$term_id.']" readonly="">'; 332 } 333 } 334 /** 335 * Edit shortcode column in category list page 336 */ 337 function wsxhi_taxonomy_edit_custom_meta_field($term) { 338 $t_id = $term->term_id; 339 ?> 399 400 /** 401 * Register filter hooks for the wsxhi_categories taxonomy columns. 402 */ 403 function RHI_category_column_hooks() { 404 $rhi_taxonomy = 'wsxhi_categories'; 405 add_filter( 'manage_' . $rhi_taxonomy . '_custom_column', 'RHI_category_column_content', 15, 3 ); 406 add_filter( 'manage_edit-' . $rhi_taxonomy . '_columns', 'RHI_category_column_header' ); 407 } 408 409 /** 410 * Define taxonomy list table columns. 411 * 412 * @param array $rhi_columns Existing columns. 413 * @return array Modified columns. 414 */ 415 function RHI_category_column_header( $rhi_columns ) { 416 $rhi_new_columns = $rhi_columns; 417 array_splice( $rhi_new_columns, 1 ); 418 $rhi_new_columns['rhi_shortcode'] = esc_html__( 'Shortcode', 'rotating-hero-image' ); 419 unset( $rhi_columns['name'] ); 420 unset( $rhi_columns['description'] ); 421 unset( $rhi_columns['slug'] ); 422 unset( $rhi_columns['short_code'] ); 423 unset( $rhi_columns['posts'] ); 424 return array_merge( 425 $rhi_columns, 426 array( 427 'name' => __( 'Name', 'rotating-hero-image' ), 428 'rhi_shortcode' => __( 'Shortcode', 'rotating-hero-image' ), 429 'slug' => __( 'Slug', 'rotating-hero-image' ), 430 'posts' => __( 'Count', 'rotating-hero-image' ), 431 ) 432 ); 433 } 434 435 /** 436 * Output the shortcode column content for each taxonomy term row. 437 * 438 * @param string $rhi_row Current column content. 439 * @param string $rhi_column_name Column being rendered. 440 * @param int $rhi_term_id Term ID. 441 * @return string Column content. 442 */ 443 function RHI_category_column_content( $rhi_row, $rhi_column_name, $rhi_term_id ) { 444 if ( 'rhi_shortcode' === $rhi_column_name ) { 445 $rhi_shortcode_val = '[wsx_hero_image catid=' . absint( $rhi_term_id ) . ']'; 446 return '<input type="text" value="' . esc_attr( $rhi_shortcode_val ) . '" readonly="" />'; 447 } 448 return $rhi_row; 449 } 450 451 /** 452 * Render the shortcode field on the category Edit Term screen. 453 * 454 * @param WP_Term $rhi_term The term being edited. 455 */ 456 function RHI_taxonomy_edit_shortcode_field( $rhi_term ) { 457 $rhi_t_id = absint( $rhi_term->term_id ); 458 ?> 340 459 <tr class="form-field"> 341 <th scope="row" valign="top"><label for="clswsxhi-shortcode"><?php _e( 'Shortcode', '' ); ?></label></th> 460 <th scope="row" valign="top"> 461 <label for="rhi-shortcode-display"><?php esc_html_e( 'Shortcode', 'rotating-hero-image' ); ?></label> 462 </th> 342 463 <td> 343 <strong><span class="clsWsxhiShortcode"><?php echo '[wsx_hero_image catid="'.esc_attr($t_id).'"]'; ?></span></strong> 464 <strong> 465 <span id="rhi-shortcode-display" class="clsWsxhiShortcode"> 466 <?php echo esc_html( '[wsx_hero_image catid="' . $rhi_t_id . '"]' ); ?> 467 </span> 468 </strong> 344 469 </td> 345 470 </tr> 346 <?php 347 } 348 ?> 471 <?php 472 } -
rotating-hero-image/trunk/public/rotating-hero-image-public.php
r2705084 r3734621 1 1 <?php 2 3 2 /** 4 3 * The public-facing functionality of the plugin. 5 4 * 6 * Defines the plugin name, version, and two examples hooks for how to 7 * enqueue the dashboard-specific stylesheet and JavaScript. 8 * 9 * @package rotating-hero-image 5 * Renders the hero image shortcode output on the frontend. 6 * 7 * @package Rotating_Hero_Image 10 8 * @subpackage rotating-hero-image/public 11 9 * @author Webstix <testing@webstix.com> 12 10 */ 13 11 14 class display_rotating_hero_image{ 15 16 public function __construct($atts) { 17 18 //add_action( 'wp_enqueue_scripts', 'wsxhi_custom_style',99 ); 19 20 RHI_FrontStyle(); 21 RHI_HeroImage($atts); 22 23 } 24 } 25 26 /** 27 * Frontend custom stylesheet. 28 */ 29 function RHI_FrontStyle(){ 30 wp_enqueue_style( 'custom_wsxhi_wp_public', plugin_dir_url( __FILE__ ).'css/custom.css', array(), '1.0.0' ); 31 } 32 33 /** 34 * Create hero_image custom post type 35 */ 36 37 function RHI_HeroImage($atts){ 38 39 $rhi_show_banner_title = get_option( 'rhi_show_banner_title'); 40 $rhi_show_banner_text = get_option( 'rhi_show_banner_text'); 41 $rhi_show_banner_button = get_option( 'rhi_show_banner_button'); 42 $rhi_width = get_option( 'rhi_width'); 43 $rhi_height = get_option( 'rhi_height'); 44 $rhi_title_font_style = get_option( 'rhi_title_font_style'); 45 $rhi_banner_text_font_style = get_option( 'rhi_banner_text_font_style'); 46 $rhi_button_color = get_option( 'rhi_button_color'); 47 $rhi_button_text_color = get_option( 'rhi_button_text_color'); 48 $rhi_title_font_color = get_option( 'rhi_title_font_color'); 49 $rhi_banner_text_font_color = get_option( 'rhi_banner_text_font_color'); 50 $rhi_opacity = get_option( 'rhi_opacity'); 51 $text_align = get_option( 'rhi_banner_text_align'); 52 $a = shortcode_atts( array( 53 'catid' => 'catid', 54 ), $atts ); 55 56 57 $args= array( 12 // If this file is called directly, abort. 13 if ( ! defined( 'WPINC' ) ) { 14 die; 15 } 16 17 /** 18 * Display class for the Rotating Hero Image shortcode. 19 * 20 * Renamed from display_rotating_hero_image to RHI_Display_Hero_Image to satisfy 21 * WordPress naming conventions (NonPrefixedClassFound rule). 22 * 23 * @since 1.0.0 24 */ 25 class RHI_Display_Hero_Image { 26 27 /** 28 * Constructor – enqueues styles and renders hero image. 29 * 30 * @param array $atts Shortcode attributes. 31 */ 32 public function __construct( $atts ) { 33 RHI_enqueue_public_style(); 34 RHI_render_hero_image( $atts ); 35 } 36 } 37 38 /** 39 * Enqueue the public-facing stylesheet. 40 */ 41 function RHI_enqueue_public_style() { 42 wp_enqueue_style( 43 'rhi_public_css', 44 plugin_dir_url( __FILE__ ) . 'css/custom.css', 45 array(), 46 RHI_PLUGIN_VERSION 47 ); 48 } 49 50 /** 51 * Query and render the rotating hero image. 52 * 53 * @param array $atts Shortcode attributes. 54 */ 55 function RHI_render_hero_image( $atts ) { 56 57 // Retrieve plugin settings. 58 $rhi_show_banner_title = get_option( 'rhi_show_banner_title' ); 59 $rhi_show_banner_text = get_option( 'rhi_show_banner_text' ); 60 $rhi_show_banner_button = get_option( 'rhi_show_banner_button' ); 61 $rhi_width = get_option( 'rhi_width' ); 62 $rhi_height = get_option( 'rhi_height' ); 63 $rhi_title_font_style = get_option( 'rhi_title_font_style' ); 64 $rhi_banner_text_font_style = get_option( 'rhi_banner_text_font_style' ); 65 $rhi_button_color = get_option( 'rhi_button_color' ); 66 $rhi_button_text_color = get_option( 'rhi_button_text_color' ); 67 $rhi_title_font_color = get_option( 'rhi_title_font_color' ); 68 $rhi_banner_text_font_color = get_option( 'rhi_banner_text_font_color' ); 69 $rhi_opacity = get_option( 'rhi_opacity' ); 70 $rhi_text_align = get_option( 'rhi_banner_text_align' ); 71 72 // Parse shortcode attributes. 73 $rhi_atts = shortcode_atts( 74 array( 'catid' => 'catid' ), 75 $atts 76 ); 77 78 // Build WP_Query arguments. 79 $rhi_query_args = array( 58 80 'post_type' => 'hero_image', 59 81 'post_status' => 'publish', 60 82 'orderby' => 'date', 61 'order' => ' asc',83 'order' => 'ASC', 62 84 'posts_per_page' => -1, 63 'orderby' => 'asc'64 85 ); 65 86 66 if($a['catid'] != 'catid'): 67 $args['tax_query'] = array( 68 array ( 87 // Apply taxonomy filter when a catid is provided. 88 // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query 89 if ( 'catid' !== $rhi_atts['catid'] ) { 90 $rhi_query_args['tax_query'] = array( // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_tax_query 91 array( 69 92 'taxonomy' => 'wsxhi_categories', 70 'field' => 'id',71 'terms' => array($a['catid']),72 ) 93 'field' => 'term_id', 94 'terms' => array( absint( $rhi_atts['catid'] ) ), 95 ), 73 96 ); 74 endif; 75 $loop= new WP_Query( $args); 76 77 while ( $loop->have_posts() ) : $loop->the_post(); global $post; 78 $hero_postid[]=$post->ID; 79 endwhile; 80 if (empty($hero_postid)) { 81 if(!empty($a['catid'])){ 82 if($a['catid']=='catid'){ 83 echo wp_kses_post("<p class='clsRHINoCat'>No hero image found</p>"); 84 } 85 else{ 86 echo wp_kses_post("<p class='clsRHINoCat'>No hero image found for the category id: ".esc_attr($a['catid'])."</p>"); 87 } 97 } 98 99 $rhi_loop = new WP_Query( $rhi_query_args ); 100 101 $rhi_post_ids = array(); 102 while ( $rhi_loop->have_posts() ) { 103 $rhi_loop->the_post(); 104 global $post; 105 $rhi_post_ids[] = $post->ID; 106 } 107 wp_reset_postdata(); 108 109 // Show friendly message when no posts are found. 110 if ( empty( $rhi_post_ids ) ) { 111 if ( 'catid' === $rhi_atts['catid'] ) { 112 echo wp_kses_post( '<p class="clsRHINoCat">No hero image found</p>' ); 113 } else { 114 echo wp_kses_post( 115 '<p class="clsRHINoCat">No hero image found for the category id: ' 116 . esc_html( $rhi_atts['catid'] ) 117 . '</p>' 118 ); 88 119 } 89 } 90 else 91 { 92 $current_postid = function ($hour) use ($hero_postid) { 93 $index = $hour / get_option('rhi_time_interval') % count($hero_postid); 94 return $hero_postid[$index]; 95 }; 96 97 $currentHour = date('G'); 98 99 $post = get_post($current_postid($currentHour)); //assuming $id has been initialized 100 setup_postdata($post); 101 $featured_img_url = get_the_post_thumbnail_url(); 102 $button_text = get_post_meta($post->ID, 'button_text', true); 103 $button_link = get_post_meta($post->ID, 'button_link', true); 104 $link_type = get_post_meta($post->ID, 'link_type', true); 105 $the_title=get_the_title(); 106 $the_content=get_the_content(); 107 $target = ''; 108 if($link_type == 'clsExternal') { 109 $target = "target='_blank'"; 110 } 111 112 $image_id = get_post_thumbnail_id(); 113 $image_alt = get_post_meta($image_id, '_wp_attachment_image_alt', TRUE); 114 115 $close_banner_title = ''; 116 $close_banner_text = ''; 117 $open_banner_title ='<'; 118 if(!empty($rhi_title_font_style)) 119 { 120 $open_banner_title .=$rhi_title_font_style; 121 } 122 if(!empty($rhi_title_font_color)) 123 { 124 $open_banner_title .=' style="color:'.$rhi_title_font_color.'"'; 125 } 126 $open_banner_title .='>'; 127 $close_banner_title .='</'.$rhi_title_font_style.'>'; 128 129 $open_banner_text ='<'; 130 if(!empty($rhi_banner_text_font_style)) 131 { 132 $open_banner_text .=$rhi_banner_text_font_style; 133 } 134 if(!empty($rhi_banner_text_font_color)) 135 { 136 $open_banner_text .=' style="color:'.$rhi_banner_text_font_color.'"'; 137 } 138 $open_banner_text .='>'; 139 $close_banner_text .='</'.$rhi_banner_text_font_style.'>'; 140 141 $open_banner_button ='<a'; 142 if(!empty($button_link)) 143 { 144 $open_banner_button .=' href="'.esc_url($button_link).'" class="Herobtn" style="text-decoration: none;'; 145 } 146 else{ 147 $open_banner_button .=' href="#" class="Herobtn" style="text-decoration: none;'; 148 } 149 150 if(!empty($rhi_button_color)) 151 { 152 $open_banner_button .='background:'.$rhi_button_color.';'; 153 } 154 155 if(!empty($rhi_button_text_color)) 156 { 157 $open_banner_button .='color:'.$rhi_button_text_color.';'; 158 } 159 if(!empty($target)) 160 { 161 $open_banner_button .='" '.$target; 162 } 163 else{ 164 $open_banner_button .='"'; 165 } 166 $open_banner_button .='>'; 167 $close_banner_button ='</a>'; 168 120 return; 121 } 122 123 // Determine which post to display based on the current hour and the time interval. 124 $rhi_current_hour = (int) wp_date( 'G' ); 125 $rhi_interval = max( 1, (int) get_option( 'rhi_time_interval' ) ); 126 $rhi_index = (int) ( ( $rhi_current_hour / $rhi_interval ) % count( $rhi_post_ids ) ); 127 $rhi_current_id = $rhi_post_ids[ $rhi_index ]; 128 129 $post = get_post( $rhi_current_id ); // phpcs:ignore WordPress.WP.GlobalVariablesOverride.Prohibited 130 setup_postdata( $post ); 131 132 $rhi_featured_img_url = get_the_post_thumbnail_url( $post->ID ); 133 $rhi_button_text = get_post_meta( $post->ID, 'button_text', true ); 134 $rhi_button_link = get_post_meta( $post->ID, 'button_link', true ); 135 $rhi_link_type = get_post_meta( $post->ID, 'link_type', true ); 136 $rhi_the_title = get_the_title( $post->ID ); 137 $rhi_the_content = get_the_content( null, false, $post->ID ); 138 $rhi_target_attr = ''; 139 140 if ( 'clsExternal' === $rhi_link_type ) { 141 $rhi_target_attr = 'target="_blank" rel="noopener noreferrer"'; 142 } 143 144 // Whitelist allowed HTML tag names for title and text wrappers. 145 $rhi_allowed_tags = array( 'h1', 'h2', 'h3', 'p', 'span' ); 146 $rhi_title_tag = in_array( $rhi_title_font_style, $rhi_allowed_tags, true ) ? $rhi_title_font_style : 'h2'; 147 $rhi_text_tag = in_array( $rhi_banner_text_font_style, $rhi_allowed_tags, true ) ? $rhi_banner_text_font_style : 'p'; 148 149 // Build opening/closing title tags. 150 $rhi_open_title = '<' . esc_attr( $rhi_title_tag ); 151 if ( ! empty( $rhi_title_font_color ) ) { 152 $rhi_open_title .= ' style="color:' . esc_attr( $rhi_title_font_color ) . '"'; 153 } 154 $rhi_open_title .= '>'; 155 $rhi_close_title = '</' . esc_attr( $rhi_title_tag ) . '>'; 156 157 // Build opening/closing text tags. 158 $rhi_open_text = '<' . esc_attr( $rhi_text_tag ); 159 if ( ! empty( $rhi_banner_text_font_color ) ) { 160 $rhi_open_text .= ' style="color:' . esc_attr( $rhi_banner_text_font_color ) . '"'; 161 } 162 $rhi_open_text .= '>'; 163 $rhi_close_text = '</' . esc_attr( $rhi_text_tag ) . '>'; 164 165 // Build button anchor tag. 166 $rhi_btn_href = ! empty( $rhi_button_link ) ? esc_url( $rhi_button_link ) : '#'; 167 $rhi_btn_style = 'text-decoration:none;'; 168 if ( ! empty( $rhi_button_color ) ) { 169 $rhi_btn_style .= 'background:' . esc_attr( $rhi_button_color ) . ';'; 170 } 171 if ( ! empty( $rhi_button_text_color ) ) { 172 $rhi_btn_style .= 'color:' . esc_attr( $rhi_button_text_color ) . ';'; 173 } 174 $rhi_open_button = '<a href="' . $rhi_btn_href . '" class="Herobtn" style="' . esc_attr( $rhi_btn_style ) . '"'; 175 if ( ! empty( $rhi_target_attr ) ) { 176 $rhi_open_button .= ' ' . $rhi_target_attr; 177 } 178 $rhi_open_button .= '>'; 179 $rhi_close_button = '</a>'; 180 181 // Build container inline style string. 182 $rhi_bg_image = ! empty( $rhi_featured_img_url ) ? 'url(' . esc_url( $rhi_featured_img_url ) . ')' : 'none'; 183 $rhi_bg_opacity = ! empty( $rhi_opacity ) ? esc_attr( $rhi_opacity ) : '0.5'; 184 $rhi_div_height = ! empty( $rhi_height ) ? absint( $rhi_height ) . 'px' : '300px'; 185 $rhi_div_width = ! empty( $rhi_width ) ? absint( $rhi_width ) . '%' : '100%'; 186 $rhi_div_align = ! empty( $rhi_text_align ) ? esc_attr( $rhi_text_align ) : 'left'; 187 188 $rhi_container_style = 189 'background-image:' . $rhi_bg_image . ';' 190 . 'background-color:rgba(255,255,255,' . $rhi_bg_opacity . ');' 191 . 'background-size:cover;' 192 . 'background-repeat:no-repeat;' 193 . 'background-blend-mode:overlay;' 194 . 'height:' . $rhi_div_height . ';' 195 . 'width:' . $rhi_div_width . ';' 196 . 'text-align:' . $rhi_div_align . ';'; 197 ?> 198 199 <div class="clsHeroImage" style="<?php echo esc_attr( $rhi_container_style ); ?>"> 200 <div class="Bannercontainer"> 201 <?php 202 if ( 'Yes' === $rhi_show_banner_title ) : 203 echo wp_kses_post( $rhi_open_title ); 204 echo wp_kses_post( $rhi_the_title ); 205 echo wp_kses_post( $rhi_close_title ); 206 endif; 207 208 if ( 'Yes' === $rhi_show_banner_text ) : 209 echo wp_kses_post( $rhi_open_text ); 210 echo wp_kses_post( $rhi_the_content ); 211 echo wp_kses_post( $rhi_close_text ); 212 endif; 213 214 if ( 'Yes' === $rhi_show_banner_button ) : 215 echo wp_kses_post( $rhi_open_button ); 216 echo wp_kses_post( $rhi_button_text ); 217 echo wp_kses_post( $rhi_close_button ); 218 endif; 169 219 ?> 170 171 <div class="clsHeroImage" style="background-image: url(<?php if(!empty($featured_img_url)) echo esc_url($featured_img_url);?>);background-color: rgba(255, 255, 255, <?php if(!empty($rhi_opacity)) echo esc_attr($rhi_opacity); ?>); background-size: cover;background-repeat:no-repeat;background-blend-mode: overlay;height:<?php if(!empty($rhi_height)) echo esc_attr($rhi_height); ?>px; width:<?php if(!empty($rhi_width)) echo esc_attr($rhi_width); ?>%;text-align: <?php if(!empty(get_option('rhi_banner_text_align'))) echo esc_attr(get_option('rhi_banner_text_align'));?>;">172 173 <div class="Bannercontainer">174 <?php175 if($rhi_show_banner_title == 'Yes'):176 if(!empty($open_banner_title)) echo wp_kses_post($open_banner_title);177 if(!empty($the_title)) echo wp_kses_post($the_title);178 if(!empty($close_banner_title)) echo wp_kses_post( $close_banner_title);179 endif;180 181 if($rhi_show_banner_text == 'Yes'):182 if(!empty($open_banner_text)) echo wp_kses_post($open_banner_text);183 if(!empty($the_content)) echo wp_kses_post($the_content);184 if(!empty($close_banner_text)) echo wp_kses_post( $close_banner_text);185 endif;186 187 if($rhi_show_banner_button == 'Yes'):188 if(!empty($open_banner_button)) echo wp_kses_post( $open_banner_button);189 if(!empty($button_text)) echo wp_kses_post($button_text);190 if(!empty($close_banner_button)) echo wp_kses_post($close_banner_button);191 endif;192 ?>193 </div>194 220 </div> 195 196 <?php 197 }221 </div> 222 223 <?php 198 224 wp_reset_postdata(); 199 225 } 200 -
rotating-hero-image/trunk/rotating-hero-image.php
r2863129 r3734621 4 4 * @link https://www.webstix.com 5 5 * @since 1.0.0 6 * 6 * 7 7 * @wordpress-plugin 8 8 * Plugin Name: Rotating Hero Image 9 9 * Plugin URI: https://www.webstix.com/wordpress-plugin-development 10 10 * Description: Display a hero banner on a page or wherever you want. Use this shortcode: <strong>[wsx_hero_image]</strong> 11 * Version: 1.0. 711 * Version: 1.0.8 12 12 * Author: Webstix 13 13 * Author URI: https://www.webstix.com 14 14 * License: GPL-2.0+ 15 15 * License URI: http://www.gnu.org/licenses/gpl-2.0.txt 16 * Text Domain: rotating-hero-image 16 17 17 18 This plugin is free software: you can redistribute it and/or modify … … 28 29 along with This plugin. If not, see {URI to Plugin License}. 29 30 */ 31 30 32 // If this file is called directly, abort. 31 33 if ( ! defined( 'WPINC' ) ) { 32 die; 33 } 34 die; 35 } 36 34 37 // Name of the plugin 35 if ( ! defined( 'RHI_PLUGIN_NAME' ) ) {38 if ( ! defined( 'RHI_PLUGIN_NAME' ) ) { 36 39 define( 'RHI_PLUGIN_NAME', 'Rotating Hero Image' ); 37 40 } 38 41 // Unique identifier for the plugin. Used as Text Domain 39 if ( ! defined( 'RHI_PLUGIN_SLUG' ) ) {42 if ( ! defined( 'RHI_PLUGIN_SLUG' ) ) { 40 43 define( 'RHI_PLUGIN_SLUG', 'rotating_hero_image' ); 41 44 } … … 45 48 } 46 49 // URL of the plugin 47 if ( ! defined( 'RHI_PLUGIN_URL' ) ) {50 if ( ! defined( 'RHI_PLUGIN_URL' ) ) { 48 51 define( 'RHI_PLUGIN_URL', plugin_dir_url( __FILE__ ) ); 49 52 } 50 // The actual l plugin version51 if ( ! defined( 'RHI_PLUGIN_VERSION' ) ) {52 define( 'RHI_PLUGIN_VERSION', '1.0. 0' );53 // The actual plugin version – synced with plugin header 54 if ( ! defined( 'RHI_PLUGIN_VERSION' ) ) { 55 define( 'RHI_PLUGIN_VERSION', '1.0.8' ); 53 56 } 57 54 58 /** 55 * Begins execution of the plugin.56 *57 * Since everything within the plugin is registered via hooks,58 * then kicking off the plugin from this point in the file does59 * not affect the page life cycle.60 *61 * @since 1.0.062 */63 /**64 59 * The core plugin class that is used to define internationalization, 65 60 * dashboard-specific hooks, and public-facing site hooks. … … 69 64 70 65 /** 71 * Begins execution of the plugin.66 * The code that runs during plugin activation. 72 67 * 73 * Since everything within the plugin is registered via hooks, 74 * then kicking off the plugin from this point in the file does 75 * not affect the page life cycle. 76 * 77 * @since 1.0.0 68 * @since 1.0.0 78 69 */ 79 function run_RotatingHeroImage() { 80 81 $plugin = new rotating_hero_image(); 82 } 83 84 register_activation_hook(__FILE__, 'RHI_cal_on_activation' ); 85 register_deactivation_hook(__FILE__, 'RHI_cal_on_deactivation' ); 86 87 /** 88 * The code that runs during plugin activation. 89 */ 90 function RHI_cal_on_activation(){ 91 flush_rewrite_rules(); 92 } 93 /** 94 * The code that runs during plugin deactivation. 95 */ 96 function RHI_cal_on_deactivation(){ 70 function RHI_cal_on_activation() { 97 71 flush_rewrite_rules(); 98 72 } 99 73 100 function RHI_hero_image_shortcode($atts){ 101 ob_start(); 102 new display_rotating_hero_image($atts); 103 return ob_get_clean(); 74 /** 75 * The code that runs during plugin deactivation. 76 * 77 * @since 1.0.0 78 */ 79 function RHI_cal_on_deactivation() { 80 flush_rewrite_rules(); 104 81 } 105 add_shortcode('wsx_hero_image', 'RHI_hero_image_shortcode');106 82 107 run_RotatingHeroImage(); 108 /* Settings link on the plugins page 109 */ 110 add_filter('plugin_action_links_' . plugin_basename(__FILE__) , 'RHI_plugin_settings_link'); 111 function RHI_plugin_settings_link($wsx_rhi_link) 112 { 113 $wsx_rhi_link[] = '<a href="' . esc_url(get_admin_url(null, 'edit.php?post_type=hero_image&page=options')) . '">' . __('Settings', 'Rotating Hero Image') . '</a>'; 114 return $wsx_rhi_link; 83 // Register activation and deactivation hooks before bootstrapping the plugin. 84 register_activation_hook( __FILE__, 'RHI_cal_on_activation' ); 85 register_deactivation_hook( __FILE__, 'RHI_cal_on_deactivation' ); 86 87 /** 88 * Begins execution of the plugin. 89 * 90 * Prefixed as RHI_run_plugin() to satisfy WordPress naming conventions 91 * (NonPrefixedFunctionFound rule). 92 * 93 * @since 1.0.0 94 */ 95 function RHI_run_plugin() { 96 new RHI_Rotating_Hero_Image(); 115 97 } 116 ?> 98 RHI_run_plugin(); 99 100 /** 101 * Shortcode handler for [wsx_hero_image]. 102 * 103 * @param array $atts Shortcode attributes. 104 * @return string Rendered HTML output. 105 */ 106 function RHI_hero_image_shortcode( $atts ) { 107 ob_start(); 108 new RHI_Display_Hero_Image( $atts ); 109 return ob_get_clean(); 110 } 111 add_shortcode( 'wsx_hero_image', 'RHI_hero_image_shortcode' ); 112 113 /** 114 * Settings link on the plugins page. 115 * 116 * @param array $RHI_links Existing plugin action links. 117 * @return array Modified plugin action links. 118 */ 119 add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), 'RHI_plugin_settings_link' ); 120 function RHI_plugin_settings_link( $RHI_links ) { 121 $RHI_links[] = '<a href="' . esc_url( get_admin_url( null, 'edit.php?post_type=hero_image&page=options' ) ) . '">' . esc_html__( 'Settings', 'rotating-hero-image' ) . '</a>'; 122 return $RHI_links; 123 } -
rotating-hero-image/trunk/uninstall.php
r2705084 r3734621 1 1 <?php 2 3 2 /** 4 3 * Fired when the plugin is uninstalled. 5 4 * 6 * When populating this file, consider the following flow 7 * of control: 5 * Removes all plugin options and custom post type data. 8 6 * 9 * - This method should be static 10 * - Check if the $_REQUEST content actually is the plugin name 11 * - Run an admin referrer check to make sure it goes through authentication 12 * - Verify the output of $_GET makes sense 13 * - Repeat with other user roles. Best directly by using the links/query string parameters. 14 * - Repeat things for multisite. Once for a single site in the network, once sitewide. 15 * 16 * This file may be updated more in future version of the Boilerplate; however, this is the 17 * general skeleton and outline for how the file should work. 18 * 19 * 7 * @package Rotating_Hero_Image 8 * @since 1.0.0 20 9 */ 21 10 22 23 // if uninstall.php is not called by WordPress, die 24 if (!defined('WP_UNINSTALL_PLUGIN')) { 11 // If uninstall.php is not called by WordPress, die. 12 if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { 25 13 die; 26 14 } 27 delete_option( 'rhi_show_banner_title');28 delete_option( 'rhi_show_banner_text');29 delete_option( 'rhi_show_banner_button');30 delete_option( 'rhi_width');31 delete_option( 'rhi_height');32 delete_option( 'rhi_opacity');33 delete_option( 'rhi_title_font_style');34 delete_option( 'rhi_banner_text_font_style');35 delete_option( 'rhi_button_color');36 delete_option( 'rhi_button_text_color');37 delete_option( 'rhi_title_font_color');38 delete_option( 'rhi_banner_text_font_color');39 delete_option( 'rhi_time_interval');40 delete_option( 'rhi_banner_text_align');41 15 42 global $wpdb; 43 // Delete all the Custom Post Types 44 $post_type = 'hero_image'; 45 $items = get_posts( array( 'post_type' =>'hero_image', 'post_status' => 'any', 'numberposts' => -1, 'fields' => 'ids' ) ); 46 47 if( $items ) { 48 foreach( $items as $item ) { 49 wp_delete_post( $item, true ); 16 // Remove all plugin options. 17 // Variable prefixed with rhi_ to satisfy WordPress.NamingConventions.PrefixAllGlobals. 18 $rhi_options_to_delete = array( 19 'rhi_show_banner_title', 20 'rhi_show_banner_text', 21 'rhi_show_banner_button', 22 'rhi_width', 23 'rhi_height', 24 'rhi_opacity', 25 'rhi_title_font_style', 26 'rhi_banner_text_font_style', 27 'rhi_button_color', 28 'rhi_button_text_color', 29 'rhi_title_font_color', 30 'rhi_banner_text_font_color', 31 'rhi_time_interval', 32 'rhi_banner_text_align', 33 ); 34 35 foreach ( $rhi_options_to_delete as $rhi_option_key ) { 36 delete_option( $rhi_option_key ); 37 } 38 39 // Delete all hero_image custom post type posts. 40 // Variable prefixed with rhi_ to satisfy WordPress.NamingConventions.PrefixAllGlobals. 41 $rhi_items = get_posts( 42 array( 43 'post_type' => 'hero_image', 44 'post_status' => 'any', 45 'numberposts' => -1, 46 'fields' => 'ids', 47 'update_post_meta_cache' => false, 48 'update_post_term_cache' => false, 49 ) 50 ); 51 52 if ( ! empty( $rhi_items ) ) { 53 foreach ( $rhi_items as $rhi_item_id ) { 54 wp_delete_post( $rhi_item_id, true ); 50 55 } 51 56 } 52 $terms = $wpdb->get_results( $wpdb->prepare( "SELECT t.name, t.term_id FROM $wpdb->terms AS t INNER JOIN $wpdb->term_taxonomy AS tt ON t.term_id = tt.term_id WHERE tt.taxonomy = 'wsxhi_categories'")); 53 foreach ($terms as $term) { 54 wp_delete_term( $term->term_id, 'wsxhi_categories' ); 57 58 // Remove taxonomy terms for wsxhi_categories. 59 // Direct DB query is intentional in uninstall context; no caching needed here. 60 global $wpdb; 61 62 $rhi_taxonomy = 'wsxhi_categories'; 63 64 // phpcs:ignore WordPress.DB.DirectDatabaseQuery.DirectQuery,WordPress.DB.DirectDatabaseQuery.NoCaching 65 $rhi_terms = $wpdb->get_results( 66 $wpdb->prepare( 67 "SELECT t.name, t.term_id 68 FROM {$wpdb->terms} AS t 69 INNER JOIN {$wpdb->term_taxonomy} AS tt ON t.term_id = tt.term_id 70 WHERE tt.taxonomy = %s", 71 $rhi_taxonomy 72 ) 73 ); 74 75 if ( ! empty( $rhi_terms ) ) { 76 foreach ( $rhi_terms as $rhi_term ) { 77 wp_delete_term( $rhi_term->term_id, $rhi_taxonomy ); 78 } 55 79 } 56 ?>
Note:
See TracChangeset
for help on using the changeset viewer.
![(please configure the [header_logo] section in trac.ini)](/chrome/site/your_project_logo.png)