assets
4 years ago
bsf-analytics
5 years ago
class-hfe-addons-actions.php
2 years ago
class-hfe-admin.php
2 years ago
class-hfe-admin.php
598 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Entry point for the plugin. Checks if Elementor is installed and activated and loads it's own files and actions. |
| 4 | * |
| 5 | * @package header-footer-elementor |
| 6 | */ |
| 7 | |
| 8 | use HFE\Lib\Astra_Target_Rules_Fields; |
| 9 | |
| 10 | defined( 'ABSPATH' ) or exit; |
| 11 | |
| 12 | /** |
| 13 | * HFE_Admin setup |
| 14 | * |
| 15 | * @since 1.0 |
| 16 | */ |
| 17 | class HFE_Admin { |
| 18 | |
| 19 | /** |
| 20 | * Instance of HFE_Admin |
| 21 | * |
| 22 | * @var HFE_Admin |
| 23 | */ |
| 24 | private static $_instance = null; |
| 25 | |
| 26 | /** |
| 27 | * Instance of HFE_Admin |
| 28 | * |
| 29 | * @return HFE_Admin Instance of HFE_Admin |
| 30 | */ |
| 31 | public static function instance() { |
| 32 | if ( ! isset( self::$_instance ) ) { |
| 33 | self::$_instance = new self(); |
| 34 | } |
| 35 | |
| 36 | add_action( 'elementor/init', __CLASS__ . '::load_admin', 0 ); |
| 37 | |
| 38 | return self::$_instance; |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Load the icons style in editor. |
| 43 | * |
| 44 | * @since 1.3.0 |
| 45 | */ |
| 46 | public static function load_admin() { |
| 47 | add_action( 'elementor/editor/after_enqueue_styles', __CLASS__ . '::hfe_admin_enqueue_scripts' ); |
| 48 | } |
| 49 | |
| 50 | /** |
| 51 | * Enqueue admin scripts |
| 52 | * |
| 53 | * @since 1.3.0 |
| 54 | * @param string $hook Current page hook. |
| 55 | * @access public |
| 56 | */ |
| 57 | public static function hfe_admin_enqueue_scripts( $hook ) { |
| 58 | |
| 59 | // Register the icons styles. |
| 60 | wp_register_style( |
| 61 | 'hfe-style', |
| 62 | HFE_URL . 'assets/css/style.css', |
| 63 | [], |
| 64 | HFE_VER |
| 65 | ); |
| 66 | |
| 67 | wp_enqueue_style( 'hfe-style' ); |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Constructor |
| 72 | */ |
| 73 | private function __construct() { |
| 74 | add_action( 'init', [ $this, 'header_footer_posttype' ] ); |
| 75 | if ( is_admin() && current_user_can( 'manage_options' ) ) { |
| 76 | add_action( 'admin_menu', [ $this, 'register_admin_menu' ], 50 ); |
| 77 | } |
| 78 | add_action( 'add_meta_boxes', [ $this, 'ehf_register_metabox' ] ); |
| 79 | add_action( 'save_post', [ $this, 'ehf_save_meta' ] ); |
| 80 | add_action( 'admin_notices', [ $this, 'location_notice' ] ); |
| 81 | add_action( 'template_redirect', [ $this, 'block_template_frontend' ] ); |
| 82 | add_filter( 'single_template', [ $this, 'load_canvas_template' ] ); |
| 83 | add_filter( 'manage_elementor-hf_posts_columns', [ $this, 'set_shortcode_columns' ] ); |
| 84 | add_action( 'manage_elementor-hf_posts_custom_column', [ $this, 'render_shortcode_column' ], 10, 2 ); |
| 85 | if ( defined( 'ELEMENTOR_PRO_VERSION' ) && ELEMENTOR_PRO_VERSION > 2.8 ) { |
| 86 | add_action( 'elementor/editor/footer', [ $this, 'register_hfe_epro_script' ], 99 ); |
| 87 | } |
| 88 | |
| 89 | if ( is_admin() ) { |
| 90 | add_action( 'manage_elementor-hf_posts_custom_column', [ $this, 'column_content' ], 10, 2 ); |
| 91 | add_filter( 'manage_elementor-hf_posts_columns', [ $this, 'column_headings' ] ); |
| 92 | require_once HFE_DIR . 'admin/class-hfe-addons-actions.php'; |
| 93 | } |
| 94 | } |
| 95 | /** |
| 96 | * Script for Elementor Pro full site editing support. |
| 97 | * |
| 98 | * @since 1.4.0 |
| 99 | * |
| 100 | * @return void |
| 101 | */ |
| 102 | public function register_hfe_epro_script() { |
| 103 | $ids_array = [ |
| 104 | [ |
| 105 | 'id' => get_hfe_header_id(), |
| 106 | 'value' => 'Header', |
| 107 | ], |
| 108 | [ |
| 109 | 'id' => get_hfe_footer_id(), |
| 110 | 'value' => 'Footer', |
| 111 | ], |
| 112 | [ |
| 113 | 'id' => hfe_get_before_footer_id(), |
| 114 | 'value' => 'Before Footer', |
| 115 | ], |
| 116 | ]; |
| 117 | |
| 118 | wp_enqueue_script( 'hfe-elementor-pro-compatibility', HFE_URL . 'inc/js/hfe-elementor-pro-compatibility.js', [ 'jquery' ], HFE_VER, true ); |
| 119 | |
| 120 | wp_localize_script( |
| 121 | 'hfe-elementor-pro-compatibility', |
| 122 | 'hfe_admin', |
| 123 | [ |
| 124 | 'ids_array' => wp_json_encode( $ids_array ), |
| 125 | ] |
| 126 | ); |
| 127 | } |
| 128 | |
| 129 | /** |
| 130 | * Adds or removes list table column headings. |
| 131 | * |
| 132 | * @param array $columns Array of columns. |
| 133 | * @return array |
| 134 | */ |
| 135 | public function column_headings( $columns ) { |
| 136 | unset( $columns['date'] ); |
| 137 | |
| 138 | $columns['elementor_hf_display_rules'] = __( 'Display Rules', 'header-footer-elementor' ); |
| 139 | $columns['date'] = __( 'Date', 'header-footer-elementor' ); |
| 140 | |
| 141 | return $columns; |
| 142 | } |
| 143 | |
| 144 | /** |
| 145 | * Adds the custom list table column content. |
| 146 | * |
| 147 | * @since 1.2.0 |
| 148 | * @param array $column Name of column. |
| 149 | * @param int $post_id Post id. |
| 150 | * @return void |
| 151 | */ |
| 152 | public function column_content( $column, $post_id ) { |
| 153 | |
| 154 | if ( 'elementor_hf_display_rules' == $column ) { |
| 155 | |
| 156 | $locations = get_post_meta( $post_id, 'ehf_target_include_locations', true ); |
| 157 | if ( ! empty( $locations ) ) { |
| 158 | echo '<div class="ast-advanced-headers-location-wrap" style="margin-bottom: 5px;">'; |
| 159 | echo '<strong>Display: </strong>'; |
| 160 | $this->column_display_location_rules( $locations ); |
| 161 | echo '</div>'; |
| 162 | } |
| 163 | |
| 164 | $locations = get_post_meta( $post_id, 'ehf_target_exclude_locations', true ); |
| 165 | if ( ! empty( $locations ) ) { |
| 166 | echo '<div class="ast-advanced-headers-exclusion-wrap" style="margin-bottom: 5px;">'; |
| 167 | echo '<strong>Exclusion: </strong>'; |
| 168 | $this->column_display_location_rules( $locations ); |
| 169 | echo '</div>'; |
| 170 | } |
| 171 | |
| 172 | $users = get_post_meta( $post_id, 'ehf_target_user_roles', true ); |
| 173 | if ( isset( $users ) && is_array( $users ) ) { |
| 174 | if ( isset( $users[0] ) && ! empty( $users[0] ) ) { |
| 175 | $user_label = []; |
| 176 | foreach ( $users as $user ) { |
| 177 | $user_label[] = Astra_Target_Rules_Fields::get_user_by_key( $user ); |
| 178 | } |
| 179 | echo '<div class="ast-advanced-headers-users-wrap">'; |
| 180 | echo '<strong>Users: </strong>'; |
| 181 | echo esc_html( join( ', ', $user_label ) ); |
| 182 | echo '</div>'; |
| 183 | } |
| 184 | } |
| 185 | } |
| 186 | } |
| 187 | |
| 188 | /** |
| 189 | * Get Markup of Location rules for Display rule column. |
| 190 | * |
| 191 | * @param array $locations Array of locations. |
| 192 | * @return void |
| 193 | */ |
| 194 | public function column_display_location_rules( $locations ) { |
| 195 | |
| 196 | $location_label = []; |
| 197 | if ( is_array( $locations ) && is_array( $locations['rule'] ) && isset( $locations['rule'] ) ) { |
| 198 | $index = array_search( 'specifics', $locations['rule'] ); |
| 199 | if ( false !== $index && ! empty( $index ) ) { |
| 200 | unset( $locations['rule'][ $index ] ); |
| 201 | } |
| 202 | } |
| 203 | |
| 204 | if ( isset( $locations['rule'] ) && is_array( $locations['rule'] ) ) { |
| 205 | foreach ( $locations['rule'] as $location ) { |
| 206 | $location_label[] = Astra_Target_Rules_Fields::get_location_by_key( $location ); |
| 207 | } |
| 208 | } |
| 209 | if ( isset( $locations['specific'] ) && is_array( $locations['specific'] ) ) { |
| 210 | foreach ( $locations['specific'] as $location ) { |
| 211 | $location_label[] = Astra_Target_Rules_Fields::get_location_by_key( $location ); |
| 212 | } |
| 213 | } |
| 214 | |
| 215 | echo esc_html( join( ', ', $location_label ) ); |
| 216 | } |
| 217 | |
| 218 | |
| 219 | /** |
| 220 | * Register Post type for Elementor Header & Footer Builder templates |
| 221 | */ |
| 222 | public function header_footer_posttype() { |
| 223 | $labels = [ |
| 224 | 'name' => esc_html__( 'Elementor Header & Footer Builder', 'header-footer-elementor' ), |
| 225 | 'singular_name' => esc_html__( 'Elementor Header & Footer Builder', 'header-footer-elementor' ), |
| 226 | 'menu_name' => esc_html__( 'Elementor Header & Footer Builder', 'header-footer-elementor' ), |
| 227 | 'name_admin_bar' => esc_html__( 'Elementor Header & Footer Builder', 'header-footer-elementor' ), |
| 228 | 'add_new' => esc_html__( 'Add New', 'header-footer-elementor' ), |
| 229 | 'add_new_item' => esc_html__( 'Add New Header or Footer', 'header-footer-elementor' ), |
| 230 | 'new_item' => esc_html__( 'New Template', 'header-footer-elementor' ), |
| 231 | 'edit_item' => esc_html__( 'Edit Template', 'header-footer-elementor' ), |
| 232 | 'view_item' => esc_html__( 'View Template', 'header-footer-elementor' ), |
| 233 | 'all_items' => esc_html__( 'All Templates', 'header-footer-elementor' ), |
| 234 | 'search_items' => esc_html__( 'Search Templates', 'header-footer-elementor' ), |
| 235 | 'parent_item_colon' => esc_html__( 'Parent Templates:', 'header-footer-elementor' ), |
| 236 | 'not_found' => esc_html__( 'No Templates found.', 'header-footer-elementor' ), |
| 237 | 'not_found_in_trash' => esc_html__( 'No Templates found in Trash.', 'header-footer-elementor' ), |
| 238 | ]; |
| 239 | |
| 240 | $args = [ |
| 241 | 'labels' => $labels, |
| 242 | 'public' => true, |
| 243 | 'show_ui' => true, |
| 244 | 'show_in_menu' => false, |
| 245 | 'show_in_nav_menus' => false, |
| 246 | 'exclude_from_search' => true, |
| 247 | 'capability_type' => 'post', |
| 248 | 'hierarchical' => false, |
| 249 | 'menu_icon' => 'dashicons-editor-kitchensink', |
| 250 | 'supports' => [ 'title', 'thumbnail', 'elementor' ], |
| 251 | ]; |
| 252 | |
| 253 | register_post_type( 'elementor-hf', $args ); |
| 254 | } |
| 255 | |
| 256 | /** |
| 257 | * Register the admin menu for Elementor Header & Footer Builder. |
| 258 | * |
| 259 | * @since 1.0.0 |
| 260 | * @since 1.0.1 |
| 261 | * Moved the menu under Appearance -> Elementor Header & Footer Builder |
| 262 | */ |
| 263 | public function register_admin_menu() { |
| 264 | add_submenu_page( |
| 265 | 'themes.php', |
| 266 | __( 'Elementor Header & Footer Builder', 'header-footer-elementor' ), |
| 267 | __( 'Elementor Header & Footer Builder', 'header-footer-elementor' ), |
| 268 | 'edit_pages', |
| 269 | 'edit.php?post_type=elementor-hf' |
| 270 | ); |
| 271 | } |
| 272 | |
| 273 | /** |
| 274 | * Register meta box(es). |
| 275 | */ |
| 276 | function ehf_register_metabox() { |
| 277 | add_meta_box( |
| 278 | 'ehf-meta-box', |
| 279 | __( 'Elementor Header & Footer Builder Options', 'header-footer-elementor' ), |
| 280 | [ |
| 281 | $this, |
| 282 | 'efh_metabox_render', |
| 283 | ], |
| 284 | 'elementor-hf', |
| 285 | 'normal', |
| 286 | 'high' |
| 287 | ); |
| 288 | } |
| 289 | |
| 290 | /** |
| 291 | * Render Meta field. |
| 292 | * |
| 293 | * @param POST $post Currennt post object which is being displayed. |
| 294 | */ |
| 295 | function efh_metabox_render( $post ) { |
| 296 | $values = get_post_custom( $post->ID ); |
| 297 | $template_type = isset( $values['ehf_template_type'] ) ? esc_attr( sanitize_text_field( $values['ehf_template_type'][0] ) ) : ''; |
| 298 | $display_on_canvas = isset( $values['display-on-canvas-template'] ) ? true : false; |
| 299 | |
| 300 | // We'll use this nonce field later on when saving. |
| 301 | wp_nonce_field( 'ehf_meta_nounce', 'ehf_meta_nounce' ); |
| 302 | ?> |
| 303 | <table class="hfe-options-table widefat"> |
| 304 | <tbody> |
| 305 | <tr class="hfe-options-row type-of-template"> |
| 306 | <td class="hfe-options-row-heading"> |
| 307 | <label for="ehf_template_type"><?php _e( 'Type of Template', 'header-footer-elementor' ); ?></label> |
| 308 | </td> |
| 309 | <td class="hfe-options-row-content"> |
| 310 | <select name="ehf_template_type" id="ehf_template_type"> |
| 311 | <option value="" <?php selected( $template_type, '' ); ?>><?php _e( 'Select Option', 'header-footer-elementor' ); ?></option> |
| 312 | <option value="type_header" <?php selected( $template_type, 'type_header' ); ?>><?php _e( 'Header', 'header-footer-elementor' ); ?></option> |
| 313 | <option value="type_before_footer" <?php selected( $template_type, 'type_before_footer' ); ?>><?php _e( 'Before Footer', 'header-footer-elementor' ); ?></option> |
| 314 | <option value="type_footer" <?php selected( $template_type, 'type_footer' ); ?>><?php _e( 'Footer', 'header-footer-elementor' ); ?></option> |
| 315 | <option value="custom" <?php selected( $template_type, 'custom' ); ?>><?php _e( 'Custom Block', 'header-footer-elementor' ); ?></option> |
| 316 | </select> |
| 317 | </td> |
| 318 | </tr> |
| 319 | |
| 320 | <?php $this->display_rules_tab(); ?> |
| 321 | <tr class="hfe-options-row hfe-shortcode"> |
| 322 | <td class="hfe-options-row-heading"> |
| 323 | <label for="ehf_template_type"><?php _e( 'Shortcode', 'header-footer-elementor' ); ?></label> |
| 324 | <i class="hfe-options-row-heading-help dashicons dashicons-editor-help" title="<?php _e( 'Copy this shortcode and paste it into your post, page, or text widget content.', 'header-footer-elementor' ); ?>"> |
| 325 | </i> |
| 326 | </td> |
| 327 | <td class="hfe-options-row-content"> |
| 328 | <span class="hfe-shortcode-col-wrap"> |
| 329 | <input type="text" onfocus="this.select();" readonly="readonly" value="[hfe_template id='<?php echo esc_attr( $post->ID ); ?>']" class="hfe-large-text code"> |
| 330 | </span> |
| 331 | </td> |
| 332 | </tr> |
| 333 | <tr class="hfe-options-row enable-for-canvas"> |
| 334 | <td class="hfe-options-row-heading"> |
| 335 | <label for="display-on-canvas-template"> |
| 336 | <?php _e( 'Enable Layout for Elementor Canvas Template?', 'header-footer-elementor' ); ?> |
| 337 | </label> |
| 338 | <i class="hfe-options-row-heading-help dashicons dashicons-editor-help" title="<?php _e( 'Enabling this option will display this layout on pages using Elementor Canvas Template.', 'header-footer-elementor' ); ?>"></i> |
| 339 | </td> |
| 340 | <td class="hfe-options-row-content"> |
| 341 | <input type="checkbox" id="display-on-canvas-template" name="display-on-canvas-template" value="1" <?php checked( $display_on_canvas, true ); ?> /> |
| 342 | </td> |
| 343 | </tr> |
| 344 | </tbody> |
| 345 | </table> |
| 346 | <?php |
| 347 | } |
| 348 | |
| 349 | /** |
| 350 | * Markup for Display Rules Tabs. |
| 351 | * |
| 352 | * @since 1.0.0 |
| 353 | */ |
| 354 | public function display_rules_tab() { |
| 355 | // Load Target Rule assets. |
| 356 | Astra_Target_Rules_Fields::get_instance()->admin_styles(); |
| 357 | |
| 358 | $include_locations = get_post_meta( get_the_id(), 'ehf_target_include_locations', true ); |
| 359 | $exclude_locations = get_post_meta( get_the_id(), 'ehf_target_exclude_locations', true ); |
| 360 | $users = get_post_meta( get_the_id(), 'ehf_target_user_roles', true ); |
| 361 | ?> |
| 362 | <tr class="bsf-target-rules-row hfe-options-row"> |
| 363 | <td class="bsf-target-rules-row-heading hfe-options-row-heading"> |
| 364 | <label><?php esc_html_e( 'Display On', 'header-footer-elementor' ); ?></label> |
| 365 | <i class="bsf-target-rules-heading-help dashicons dashicons-editor-help" |
| 366 | title="<?php echo esc_attr__( 'Add locations for where this template should appear.', 'header-footer-elementor' ); ?>"></i> |
| 367 | </td> |
| 368 | <td class="bsf-target-rules-row-content hfe-options-row-content"> |
| 369 | <?php |
| 370 | Astra_Target_Rules_Fields::target_rule_settings_field( |
| 371 | 'bsf-target-rules-location', |
| 372 | [ |
| 373 | 'title' => __( 'Display Rules', 'header-footer-elementor' ), |
| 374 | 'value' => '[{"type":"basic-global","specific":null}]', |
| 375 | 'tags' => 'site,enable,target,pages', |
| 376 | 'rule_type' => 'display', |
| 377 | 'add_rule_label' => __( 'Add Display Rule', 'header-footer-elementor' ), |
| 378 | ], |
| 379 | $include_locations |
| 380 | ); |
| 381 | ?> |
| 382 | </td> |
| 383 | </tr> |
| 384 | <tr class="bsf-target-rules-row hfe-options-row"> |
| 385 | <td class="bsf-target-rules-row-heading hfe-options-row-heading"> |
| 386 | <label><?php esc_html_e( 'Do Not Display On', 'header-footer-elementor' ); ?></label> |
| 387 | <i class="bsf-target-rules-heading-help dashicons dashicons-editor-help" |
| 388 | title="<?php echo esc_attr__( 'Add locations for where this template should not appear.', 'header-footer-elementor' ); ?>"></i> |
| 389 | </td> |
| 390 | <td class="bsf-target-rules-row-content hfe-options-row-content"> |
| 391 | <?php |
| 392 | Astra_Target_Rules_Fields::target_rule_settings_field( |
| 393 | 'bsf-target-rules-exclusion', |
| 394 | [ |
| 395 | 'title' => __( 'Exclude On', 'header-footer-elementor' ), |
| 396 | 'value' => '[]', |
| 397 | 'tags' => 'site,enable,target,pages', |
| 398 | 'add_rule_label' => __( 'Add Exclusion Rule', 'header-footer-elementor' ), |
| 399 | 'rule_type' => 'exclude', |
| 400 | ], |
| 401 | $exclude_locations |
| 402 | ); |
| 403 | ?> |
| 404 | </td> |
| 405 | </tr> |
| 406 | <tr class="bsf-target-rules-row hfe-options-row"> |
| 407 | <td class="bsf-target-rules-row-heading hfe-options-row-heading"> |
| 408 | <label><?php esc_html_e( 'User Roles', 'header-footer-elementor' ); ?></label> |
| 409 | <i class="bsf-target-rules-heading-help dashicons dashicons-editor-help" title="<?php echo esc_attr__( 'Display custom template based on user role.', 'header-footer-elementor' ); ?>"></i> |
| 410 | </td> |
| 411 | <td class="bsf-target-rules-row-content hfe-options-row-content"> |
| 412 | <?php |
| 413 | Astra_Target_Rules_Fields::target_user_role_settings_field( |
| 414 | 'bsf-target-rules-users', |
| 415 | [ |
| 416 | 'title' => __( 'Users', 'header-footer-elementor' ), |
| 417 | 'value' => '[]', |
| 418 | 'tags' => 'site,enable,target,pages', |
| 419 | 'add_rule_label' => __( 'Add User Rule', 'header-footer-elementor' ), |
| 420 | ], |
| 421 | $users |
| 422 | ); |
| 423 | ?> |
| 424 | </td> |
| 425 | </tr> |
| 426 | <?php |
| 427 | } |
| 428 | |
| 429 | /** |
| 430 | * Save meta field. |
| 431 | * |
| 432 | * @param POST $post_id Currennt post object which is being displayed. |
| 433 | * |
| 434 | * @return Void |
| 435 | */ |
| 436 | public function ehf_save_meta( $post_id ) { |
| 437 | |
| 438 | // Bail if we're doing an auto save. |
| 439 | if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { |
| 440 | return; |
| 441 | } |
| 442 | |
| 443 | // if our nonce isn't there, or we can't verify it, bail. |
| 444 | if ( ! isset( $_POST['ehf_meta_nounce'] ) || ! wp_verify_nonce( sanitize_text_field( $_POST['ehf_meta_nounce'] ), 'ehf_meta_nounce' ) ) { |
| 445 | return; |
| 446 | } |
| 447 | |
| 448 | // if our current user can't edit this post, bail. |
| 449 | if ( ! current_user_can( 'edit_posts' ) ) { |
| 450 | return; |
| 451 | } |
| 452 | |
| 453 | $target_locations = Astra_Target_Rules_Fields::get_format_rule_value( $_POST, 'bsf-target-rules-location' ); |
| 454 | $target_exclusion = Astra_Target_Rules_Fields::get_format_rule_value( $_POST, 'bsf-target-rules-exclusion' ); |
| 455 | $target_users = []; |
| 456 | |
| 457 | if ( isset( $_POST['bsf-target-rules-users'] ) ) { |
| 458 | $target_users = array_map( 'sanitize_text_field', $_POST['bsf-target-rules-users'] ); |
| 459 | } |
| 460 | |
| 461 | update_post_meta( $post_id, 'ehf_target_include_locations', $target_locations ); |
| 462 | update_post_meta( $post_id, 'ehf_target_exclude_locations', $target_exclusion ); |
| 463 | update_post_meta( $post_id, 'ehf_target_user_roles', $target_users ); |
| 464 | |
| 465 | if ( isset( $_POST['ehf_template_type'] ) ) { |
| 466 | update_post_meta( $post_id, 'ehf_template_type', sanitize_text_field( $_POST['ehf_template_type'] ) ); |
| 467 | } |
| 468 | |
| 469 | if ( isset( $_POST['display-on-canvas-template'] ) ) { |
| 470 | update_post_meta( $post_id, 'display-on-canvas-template', sanitize_text_field( $_POST['display-on-canvas-template'] ) ); |
| 471 | } else { |
| 472 | delete_post_meta( $post_id, 'display-on-canvas-template' ); |
| 473 | } |
| 474 | } |
| 475 | |
| 476 | /** |
| 477 | * Display notice when editing the header or footer when there is one more of similar layout is active on the site. |
| 478 | * |
| 479 | * @since 1.0.0 |
| 480 | */ |
| 481 | public function location_notice() { |
| 482 | global $pagenow; |
| 483 | global $post; |
| 484 | |
| 485 | if ( 'post.php' != $pagenow || ! is_object( $post ) || 'elementor-hf' != $post->post_type ) { |
| 486 | return; |
| 487 | } |
| 488 | |
| 489 | $template_type = get_post_meta( $post->ID, 'ehf_template_type', true ); |
| 490 | |
| 491 | if ( '' !== $template_type ) { |
| 492 | $templates = Header_Footer_Elementor::get_template_id( $template_type ); |
| 493 | |
| 494 | // Check if more than one template is selected for current template type. |
| 495 | if ( is_array( $templates ) && isset( $templates[1] ) && $post->ID != $templates[0] ) { |
| 496 | $post_title = '<strong>' . esc_html( get_the_title( $templates[0] ) ) . '</strong>'; |
| 497 | $template_location = '<strong>' . esc_html( $this->template_location( $template_type ) ) . '</strong>'; |
| 498 | /* Translators: Post title, Template Location */ |
| 499 | $message = sprintf( __( 'Template %1$s is already assigned to the location %2$s', 'header-footer-elementor' ), $post_title, $template_location ); |
| 500 | |
| 501 | echo '<div class="error"><p>'; |
| 502 | echo esc_html( $message ); |
| 503 | echo '</p></div>'; |
| 504 | } |
| 505 | } |
| 506 | } |
| 507 | |
| 508 | /** |
| 509 | * Convert the Template name to be added in the notice. |
| 510 | * |
| 511 | * @since 1.0.0 |
| 512 | * |
| 513 | * @param String $template_type Template type name. |
| 514 | * |
| 515 | * @return String $template_type Template type name. |
| 516 | */ |
| 517 | public function template_location( $template_type ) { |
| 518 | $template_type = ucfirst( str_replace( 'type_', '', $template_type ) ); |
| 519 | |
| 520 | return $template_type; |
| 521 | } |
| 522 | |
| 523 | /** |
| 524 | * Don't display the elementor Elementor Header & Footer Builder templates on the frontend for non edit_posts capable users. |
| 525 | * |
| 526 | * @since 1.0.0 |
| 527 | */ |
| 528 | public function block_template_frontend() { |
| 529 | if ( is_singular( 'elementor-hf' ) && ! current_user_can( 'edit_posts' ) ) { |
| 530 | wp_redirect( site_url(), 301 ); |
| 531 | die; |
| 532 | } |
| 533 | } |
| 534 | |
| 535 | /** |
| 536 | * Single template function which will choose our template |
| 537 | * |
| 538 | * @since 1.0.1 |
| 539 | * |
| 540 | * @param String $single_template Single template. |
| 541 | */ |
| 542 | function load_canvas_template( $single_template ) { |
| 543 | global $post; |
| 544 | |
| 545 | if ( 'elementor-hf' == $post->post_type ) { |
| 546 | $elementor_2_0_canvas = ELEMENTOR_PATH . '/modules/page-templates/templates/canvas.php'; |
| 547 | |
| 548 | if ( file_exists( $elementor_2_0_canvas ) ) { |
| 549 | return $elementor_2_0_canvas; |
| 550 | } else { |
| 551 | return ELEMENTOR_PATH . '/includes/page-templates/canvas.php'; |
| 552 | } |
| 553 | } |
| 554 | |
| 555 | return $single_template; |
| 556 | } |
| 557 | |
| 558 | /** |
| 559 | * Set shortcode column for template list. |
| 560 | * |
| 561 | * @param array $columns template list columns. |
| 562 | */ |
| 563 | function set_shortcode_columns( $columns ) { |
| 564 | $date_column = $columns['date']; |
| 565 | |
| 566 | unset( $columns['date'] ); |
| 567 | |
| 568 | $columns['shortcode'] = __( 'Shortcode', 'header-footer-elementor' ); |
| 569 | $columns['date'] = $date_column; |
| 570 | |
| 571 | return $columns; |
| 572 | } |
| 573 | |
| 574 | /** |
| 575 | * Display shortcode in template list column. |
| 576 | * |
| 577 | * @param array $column template list column. |
| 578 | * @param int $post_id post id. |
| 579 | */ |
| 580 | function render_shortcode_column( $column, $post_id ) { |
| 581 | switch ( $column ) { |
| 582 | case 'shortcode': |
| 583 | ob_start(); |
| 584 | ?> |
| 585 | <span class="hfe-shortcode-col-wrap"> |
| 586 | <input type="text" onfocus="this.select();" readonly="readonly" value="[hfe_template id='<?php echo esc_attr( $post_id ); ?>']" class="hfe-large-text code"> |
| 587 | </span> |
| 588 | |
| 589 | <?php |
| 590 | |
| 591 | ob_get_contents(); |
| 592 | break; |
| 593 | } |
| 594 | } |
| 595 | } |
| 596 | |
| 597 | HFE_Admin::instance(); |
| 598 |