ajax.php
2 months ago
custom-post.php
3 years ago
metabox.php
2 years ago
migration.php
2 years ago
resize.php
3 years ago
settings.php
4 years ago
shortcode.php
1 year ago
widget.php
4 years ago
metabox.php
124 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Exit if accessed directly |
| 4 | */ |
| 5 | if ( ! defined( 'ABSPATH' ) ) { |
| 6 | exit; |
| 7 | } |
| 8 | |
| 9 | class PGCU_Metabox |
| 10 | { |
| 11 | |
| 12 | public function __construct () { |
| 13 | //add metabox |
| 14 | add_action( 'add_meta_boxes', array( $this,'gc_adl_add_meta_box' ) ); |
| 15 | |
| 16 | //save post |
| 17 | add_action( 'save_post', array( $this,'gc_adl_save_meta_box' ) ); |
| 18 | |
| 19 | } |
| 20 | |
| 21 | //method for add meta box |
| 22 | public function gc_adl_add_meta_box() { |
| 23 | add_meta_box( |
| 24 | 'short_metabox', |
| 25 | __( 'Settings & Shortcode Generator', PGCU_TEXTDOMAIN ), |
| 26 | array( $this,'outpost_shortcode_metabox_markup' ), |
| 27 | PGCU_POST_TYPE, |
| 28 | 'normal' |
| 29 | ); |
| 30 | } |
| 31 | |
| 32 | //Function that will check if value is a valid HEX color. |
| 33 | public function check_color( $value ) { |
| 34 | |
| 35 | if ( preg_match( '/^#[a-f0-9]{6}$/i', $value ) ) { // if user insert a HEX color with # |
| 36 | return true; |
| 37 | } |
| 38 | |
| 39 | return false; |
| 40 | } |
| 41 | |
| 42 | //output of shortcode metabox |
| 43 | public function outpost_shortcode_metabox_markup( $post ){ |
| 44 | |
| 45 | // Add a nonce field so we can check for it later. |
| 46 | wp_nonce_field( 'aps_meta_save', 'gc_meta_save_nonce' ); |
| 47 | |
| 48 | $get_value = get_post_meta( $post->ID,'gc',true ); |
| 49 | $get_value = ! is_array( $get_value ) ? post_grid_and_carousel_ultimate::json_decoded( $get_value ) : $get_value; |
| 50 | |
| 51 | $gc_value = is_array( $get_value ) ? $get_value : array(); |
| 52 | |
| 53 | extract( $gc_value ); |
| 54 | |
| 55 | $layout = ! empty( $layout ) ? $layout : 'carousel'; |
| 56 | ?> |
| 57 | <div id="tabs-container"> |
| 58 | <div class="lcsp-tabs-menu-wrapper"> |
| 59 | <ul class="lcsp-tabs-menu"> |
| 60 | <li class="current"><a href="#tab-1"> <?php esc_html_e( 'Shortcodes', PGCU_TEXTDOMAIN ); ?> </a></li> |
| 61 | |
| 62 | <li><a href="#tab-2"> <?php esc_html_e( 'General Settings', PGCU_TEXTDOMAIN ); ?> </a></li> |
| 63 | |
| 64 | <li style="display: <?php if( $layout == "grid" || $layout == "isotope" ) { echo "none"; }else{ echo "block"; }?>;" id="tab1"><a href="#tab-3"> <?php esc_html_e( 'Carousel Settings', PGCU_TEXTDOMAIN ); ?> </a></li> |
| 65 | |
| 66 | <li style="display: <?php if( $layout == "grid" ){ echo "block"; }else{ echo "none"; }?>;" id="tab2"><a href="#tab-4"> <?php esc_html_e( 'Grid Settings', PGCU_TEXTDOMAIN ); ?> </a></li> |
| 67 | |
| 68 | <li style="display: <?php if( $layout == "isotope" ){ echo "block"; }else{ echo "none"; }?>;" id="tab3"><a href="#tab-5"> <?php esc_html_e( 'Sortable Grid Settings', PGCU_TEXTDOMAIN ); ?> </a></li> |
| 69 | |
| 70 | <li><a href="#tab-6"> <?php esc_html_e( 'Style Settings', PGCU_TEXTDOMAIN ); ?> </a></li> |
| 71 | </ul> |
| 72 | <a href="https://wpwax.com/contact/" class="lcsp-support"><span class="fas fa-question-circle"></span>Support</a> |
| 73 | </div> |
| 74 | <?php |
| 75 | require_once PGCU_INC_DIR . 'settings/get-shortcodes.php'; |
| 76 | require_once PGCU_INC_DIR . 'settings/general.php'; |
| 77 | require_once PGCU_INC_DIR . 'settings/grid.php'; |
| 78 | require_once PGCU_INC_DIR . 'settings/carousel.php'; |
| 79 | require_once PGCU_INC_DIR . 'settings/sortable.php'; |
| 80 | require_once PGCU_INC_DIR . 'settings/style.php'; |
| 81 | |
| 82 | } |
| 83 | |
| 84 | //save all posts |
| 85 | public function gc_adl_save_meta_box( $post_id ) |
| 86 | { |
| 87 | // vail if the security check fails |
| 88 | if ( ! $this->wcpscu_security_check( 'gc_meta_save_nonce', 'aps_meta_save', $post_id ) ) |
| 89 | return; |
| 90 | |
| 91 | |
| 92 | // save the meta data if it is our post type lcg_mainpost post type |
| 93 | if ( ! empty( $_POST['post_type'] ) && ( PGCU_POST_TYPE == $_POST['post_type'] ) ) { |
| 94 | |
| 95 | $gc = ! empty( $_POST['gc'] ) ? post_grid_and_carousel_ultimate::json_encoded( pgcu_sanitize_array( $_POST['gc'] ) ) : post_grid_and_carousel_ultimate::json_encoded( array() ); |
| 96 | |
| 97 | //save the meta value |
| 98 | update_post_meta( $post_id, "gc", $gc ); |
| 99 | |
| 100 | } |
| 101 | } |
| 102 | |
| 103 | //security check |
| 104 | private function wcpscu_security_check( $nonce_name, $action, $post_id ) { |
| 105 | // checks are divided into 3 parts for readability. |
| 106 | if ( ! empty( $_POST[ $nonce_name ] ) && wp_verify_nonce( $_POST[ $nonce_name ], $action ) ) { |
| 107 | return true; |
| 108 | } |
| 109 | // If this is an autosave, our form has not been submitted, so we don't want to do anything. returns false |
| 110 | if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { |
| 111 | return false; |
| 112 | } |
| 113 | // Check the user's permissions. |
| 114 | if ( current_user_can( 'edit_post', $post_id ) ) { |
| 115 | return true; |
| 116 | } |
| 117 | |
| 118 | return false; |
| 119 | } |
| 120 | |
| 121 | |
| 122 | |
| 123 | } // end class |
| 124 |