array( 'menu_name' => _x( 'Product Filters', 'Admin menu name', 'BeRocket_AJAX_domain' ), 'add_new_item' => __( 'Add New Filter', 'BeRocket_AJAX_domain' ), 'edit' => __( 'Edit', 'BeRocket_AJAX_domain' ), 'edit_item' => __( 'Edit Filter', 'BeRocket_AJAX_domain' ), 'new_item' => __( 'New Filter', 'BeRocket_AJAX_domain' ), 'view' => __( 'View Filters', 'BeRocket_AJAX_domain' ), 'view_item' => __( 'View Filter', 'BeRocket_AJAX_domain' ), 'search_items' => __( 'Search Product Filters', 'BeRocket_AJAX_domain' ), 'not_found' => __( 'No Product Filters found', 'BeRocket_AJAX_domain' ), 'not_found_in_trash' => __( 'No Product Filters found in trash', 'BeRocket_AJAX_domain' ), ), 'description' => __( 'This is where you can add Product Filters.', 'BeRocket_AJAX_domain' ), 'public' => true, 'show_ui' => true, 'capability_type' => 'post', 'publicly_queryable' => false, 'exclude_from_search' => true, 'show_in_menu' => 'edit.php?post_type=product', 'hierarchical' => false, 'rewrite' => false, 'query_var' => false, 'supports' => array( 'title' ), 'show_in_nav_menus' => false, ) */ if ( ! class_exists('BeRocket_custom_post_class') ) { class BeRocket_custom_post_class { public $meta_boxes = array(); public $default_settings = array(); public $post_settings, $post_name; public $post_type_parameters = array(); protected static $instance; public static function getInstance() { if (null === static::$instance) { static::$instance = new static(); } return static::$instance; } function __construct () { if (null === static::$instance) { static::$instance = $this; } $this->post_type_parameters = array_merge(array( 'sortable' => false ), $this->post_type_parameters); add_filter( 'init', array( $this, 'init' ) ); add_filter( 'admin_init', array( $this, 'admin_init' ), 15 ); add_filter( 'wp_insert_post_data', array( $this, 'wp_insert_post_data' ), 30, 2 ); if( $this->post_type_parameters['sortable'] ) { if( is_admin() ) { add_action('berocket_custom_post_'.$this->post_name.'_admin_init', array($this, 'sortable_admin_init')); add_action('berocket_custom_post_'.$this->post_name.'_wc_save_product_before', array($this, 'sortable_wc_save_product_before'), 10, 2); add_action('berocket_custom_post_'.$this->post_name.'_wc_save_product_without_check_before', array($this, 'sortable_wc_save_product_before'), 10, 2); add_action('berocket_custom_post_'.$this->post_name.'_columns_replace', array($this, 'sortable_columns_replace'), 10, 1); add_filter('berocket_custom_post_'.$this->post_name.'_manage_edit_columns', array($this, 'sortable_manage_edit_columns')); } add_filter('berocket_custom_post_'.$this->post_name.'_get_custom_posts_args_default', array($this, 'sortable_get_custom_post')); } } function init() { $this->default_settings = apply_filters('berocket_custom_post_'.$this->post_name.'_default_settings', $this->default_settings, self::$instance); register_post_type( $this->post_name, $this->post_settings); } public function get_custom_posts($args = array()) { $args = array_merge(apply_filters( 'berocket_custom_post_'.$this->post_name.'_get_custom_posts_args_default', array( 'posts_per_page' => -1, 'offset' => 0, 'category' => '', 'category_name' => '', 'include' => '', 'exclude' => '', 'meta_key' => '', 'meta_value' => '', 'post_type' => $this->post_name, 'post_mime_type' => '', 'post_parent' => '', 'author' => '', 'post_status' => 'publish', 'fields' => 'ids', 'suppress_filters' => false ) ), $args); $posts_array = new WP_Query($args); $posts_array = $posts_array->posts; return $posts_array; } public function add_meta_box($slug, $name, $callback = false, $position = 'normal', $priority = 'high') { if( $callback === false ) { $callback = array($this, $slug); } $this->meta_boxes[$slug] = array('slug' => $slug, 'name' => $name, 'callback' => $callback, 'position' => $position, 'priority' => $priority); } public function admin_init() { global $pagenow; if( 'edit.php' == $pagenow && isset( $_GET['post_type'] ) && $_GET['post_type'] == $this->post_name ){ wp_enqueue_script( 'berocket_framework_admin' ); wp_enqueue_style( 'berocket_framework_admin_style' ); } add_filter( 'bulk_actions-edit-'.$this->post_name, array( $this, 'bulk_actions_edit' ) ); add_filter( 'views_edit-'.$this->post_name, array( $this, 'views_edit' ) ); add_filter( 'manage_edit-'.$this->post_name.'_columns', array( $this, 'manage_edit_columns' ) ); add_action( 'manage_'.$this->post_name.'_posts_custom_column', array( $this, 'columns_replace' ), 2 ); add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) ); add_action( 'save_post', array( $this, 'wc_save_product' ), 10, 2 ); add_filter( 'post_row_actions', array( $this, 'post_row_actions' ), 10, 2 ); add_filter( 'list_table_primary_column', array( $this, 'list_table_primary_column' ), 10, 2 ); add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_scripts' ) ); do_action( 'berocket_custom_post_'.$this->post_name.'_admin_init', $this->post_type_parameters); } public function admin_enqueue_scripts() { global $post; if ( ! empty( $post ) and $post->post_type == $this->post_name ) { wp_register_style( 'font-awesome', plugins_url( '../assets/css/font-awesome.min.css', __FILE__ ) ); } } public function post_row_actions($actions, $post) { if( $post->post_type == $this->post_name ) { if( isset($actions['inline hide-if-no-js']) ) { unset($actions['inline hide-if-no-js']); } } return $actions; } public function list_table_primary_column($default, $screen_id) { if( $screen_id == 'edit-'.$this->post_name ) { $default = 'name'; } return $default; } public function bulk_actions_edit ( $actions ) { unset( $actions['edit'] ); return $actions; } public function views_edit ( $view ) { unset( $view['publish'], $view['private'], $view['future'] ); return $view; } public function manage_edit_columns ( $columns ) { $columns = array(); $columns["cb"] = ''; $columns["name"] = __( "Name", 'BeRocket_domain' ); $columns = apply_filters( 'berocket_custom_post_'.$this->post_name.'_manage_edit_columns', $columns, $this->post_type_parameters); return $columns; } public function columns_replace ( $column ) { global $post; switch ( $column ) { case "name": $edit_link = get_edit_post_link( $post->ID ); $title = '' . _draft_or_post_title() . ''; echo 'ID:' . $post->ID . ' ' . $title . ''; break; default: break; } do_action( 'berocket_custom_post_'.$this->post_name.'_columns_replace', $column, $this->post_type_parameters); } public function add_meta_boxes () { add_meta_box( 'submitdiv', __( 'Save content', 'BeRocket_domain' ), array( $this, 'save_meta_box' ), $this->post_name, 'side', 'high' ); add_meta_box( 'copysettingsfromdiv', __( 'Copy settings from', 'BeRocket_domain' ), array( $this, 'copy_settings_from' ), $this->post_name, 'side', 'high' ); foreach($this->meta_boxes as $meta_box) { add_meta_box( $meta_box['slug'], $meta_box['name'], $meta_box['callback'], $this->post_name, $meta_box['position'], $meta_box['priority'] ); } } public function copy_settings_from($post) { $posts_array = $this->get_custom_posts(); ?>