assets
1 week ago
theme-hooks
4 years ago
views
1 week ago
activator.php
2 years ago
cpt-api.php
4 years ago
cpt-hooks.php
2 years ago
cpt.php
1 year ago
init.php
1 week ago
cpt-hooks.php
116 lines
| 1 | <?php |
| 2 | namespace ElementsKit_Lite\Modules\Header_Footer; |
| 3 | |
| 4 | defined( 'ABSPATH' ) || exit; |
| 5 | |
| 6 | class Cpt_Hooks { |
| 7 | public static $instance = null; |
| 8 | |
| 9 | public function __construct() { |
| 10 | |
| 11 | add_action( 'admin_init', array( $this, 'add_author_support_to_column' ), 10 ); |
| 12 | add_filter( 'manage_elementskit_template_posts_columns', array( $this, 'set_columns' ) ); |
| 13 | add_action( 'manage_elementskit_template_posts_custom_column', array( $this, 'render_column' ), 10, 2 ); |
| 14 | add_filter( 'parse_query', array( $this, 'query_filter' ) ); |
| 15 | } |
| 16 | |
| 17 | public function add_author_support_to_column() { |
| 18 | add_post_type_support( 'elementskit_template', 'author' ); |
| 19 | } |
| 20 | |
| 21 | /** |
| 22 | * Set custom column for template list. |
| 23 | */ |
| 24 | public function set_columns( $columns ) { |
| 25 | |
| 26 | $date_column = $columns['date']; |
| 27 | $author_column = $columns['author']; |
| 28 | |
| 29 | unset( $columns['date'] ); |
| 30 | unset( $columns['author'] ); |
| 31 | |
| 32 | $columns['type'] = esc_html__( 'Type', 'elementskit-lite' ); |
| 33 | $columns['condition'] = esc_html__( 'Conditions', 'elementskit-lite' ); |
| 34 | $columns['date'] = $date_column; |
| 35 | $columns['author'] = $author_column; |
| 36 | |
| 37 | return $columns; |
| 38 | } |
| 39 | |
| 40 | /** |
| 41 | * Render Column |
| 42 | * |
| 43 | * Enqueue js and css to frontend. |
| 44 | * |
| 45 | * @since 1.0.0 |
| 46 | * @access public |
| 47 | */ |
| 48 | public function render_column( $column, $post_id ) { |
| 49 | switch ( $column ) { |
| 50 | case 'type': |
| 51 | $type = get_post_meta( $post_id, 'elementskit_template_type', true ); |
| 52 | $active = get_post_meta( $post_id, 'elementskit_template_activation', true ); |
| 53 | |
| 54 | $output = ucfirst( $type ) . ( ( $active == 'yes' ) |
| 55 | ? ( '<span class="ekit-headerfooter-status ekit-headerfooter-status-active">' . esc_html__( 'Active', 'elementskit-lite' ) . '</span>' ) |
| 56 | : ( '<span class="ekit-headerfooter-status ekit-headerfooter-status-inactive">' . esc_html__( 'Inactive', 'elementskit-lite' ) . '</span>' ) ); |
| 57 | |
| 58 | echo wp_kses($output, \ElementsKit_Lite\Utils::get_kses_array()); |
| 59 | |
| 60 | break; |
| 61 | case 'condition': |
| 62 | $cond = array( |
| 63 | 'condition_a' => get_post_meta( $post_id, 'elementskit_template_condition_a', true ), |
| 64 | 'condition_singular' => get_post_meta( $post_id, 'elementskit_template_condition_singular', true ), |
| 65 | 'condition_singular_id' => get_post_meta( $post_id, 'elementskit_template_condition_singular_id', true ), |
| 66 | ); |
| 67 | |
| 68 | echo esc_html(ucwords( |
| 69 | str_replace( |
| 70 | '_', |
| 71 | ' ', |
| 72 | $cond['condition_a'] |
| 73 | . ( ( $cond['condition_a'] == 'singular' ) |
| 74 | ? ( ( $cond['condition_singular'] != '' ) |
| 75 | ? ( ' > ' . $cond['condition_singular'] |
| 76 | . ( ( $cond['condition_singular_id'] != '' ) |
| 77 | ? ' > ' . $cond['condition_singular_id'] |
| 78 | : '' ) ) |
| 79 | : '' ) |
| 80 | : '' ) |
| 81 | ) |
| 82 | )); |
| 83 | |
| 84 | break; |
| 85 | } |
| 86 | } |
| 87 | |
| 88 | |
| 89 | public function query_filter( $query ) { |
| 90 | global $pagenow; |
| 91 | $current_page = isset( $_GET['post_type'] ) ? sanitize_text_field(wp_unslash($_GET['post_type'])) : ''; // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- We are using wordpress default query filter for managing menu items |
| 92 | |
| 93 | if ( is_admin() |
| 94 | && 'elementskit_template' == $current_page |
| 95 | && 'edit.php' == $pagenow |
| 96 | && isset( $_GET['elementskit_type_filter'] ) // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- We are using wordpress default query filter for managing menu items |
| 97 | && $_GET['elementskit_type_filter'] != '' // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- We are using wordpress default query filter for managing menu items |
| 98 | && $_GET['elementskit_type_filter'] != 'all' // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- We are using wordpress default query filter for managing menu items |
| 99 | ) { |
| 100 | $type = sanitize_text_field(wp_unslash($_GET['elementskit_type_filter'])); // phpcs:ignore WordPress.Security.NonceVerification.Recommended -- We are using wordpress default query filter for managing menu items |
| 101 | $query->query_vars['meta_key'] = 'elementskit_template_type'; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_key |
| 102 | $query->query_vars['meta_value'] = $type; // phpcs:ignore WordPress.DB.SlowDBQuery.slow_db_query_meta_value |
| 103 | $query->query_vars['meta_compare'] = '='; |
| 104 | } |
| 105 | } |
| 106 | |
| 107 | |
| 108 | public static function instance() { |
| 109 | if ( is_null( self::$instance ) ) { |
| 110 | self::$instance = new self(); |
| 111 | } |
| 112 | |
| 113 | return self::$instance; |
| 114 | } |
| 115 | } |
| 116 |