*/ class TICA_Initiatives_Admin { /** * The ID of this plugin. * * @since 1.0.0 * @access private * @var string $plugin_name The ID of this plugin. */ private $plugin_name; /** * The version of this plugin. * * @since 1.0.0 * @access private * @var string $version The current version of this plugin. */ private $version; /** * Initialize the class and set its properties. * * @since 1.0.0 * @param string $plugin_name The name of this plugin. * @param string $version The version of this plugin. */ public function __construct( $plugin_name, $version ) { $this->plugin_name = $plugin_name; $this->version = $version; } /** * Register the stylesheets for the admin area. * * @since 1.0.0 */ public function enqueue_styles() { /** * This function is provided for demonstration purposes only. * * An instance of this class should be passed to the run() function * defined in TICA_Initiatives_Loader as all of the hooks are defined * in that particular class. * * The TICA_Initiatives_Loader will then create the relationship * between the defined hooks and the functions defined in this * class. */ wp_enqueue_style( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'css/tica-initiatives-admin.css', array(), $this->version, 'all' ); } /** * Register the JavaScript for the admin area. * * @since 1.0.0 */ public function enqueue_scripts() { /** * This function is provided for demonstration purposes only. * * An instance of this class should be passed to the run() function * defined in TICA_Initiatives_Loader as all of the hooks are defined * in that particular class. * * The TICA_Initiatives_Loader will then create the relationship * between the defined hooks and the functions defined in this * class. */ wp_enqueue_script( $this->plugin_name, plugin_dir_url( __FILE__ ) . 'js/tica-initiatives-admin.js', array( 'jquery' ), $this->version, false ); } public function register_initiative_cpt() { $labels = array( 'name' => _x( 'Initiatives', 'Post Type General Name', 'tica-initiatives' ), 'singular_name' => _x( 'Initiative', 'Post Type Singular Name', 'tica-initiatives' ), 'menu_name' => __( 'TICA Initiatives', 'tica-initiatives' ), 'name_admin_bar' => __( 'Initiative Type', 'tica-initiatives' ), 'archives' => __( 'Initiative Archives', 'tica-initiatives' ), 'attributes' => __( 'Initiative Attributes', 'tica-initiatives' ), 'parent_item_colon' => __( 'Parent Item:', 'tica-initiatives' ), 'all_items' => __( 'All Initiatives', 'tica-initiatives' ), 'add_new_item' => __( 'Add New Initiative', 'tica-initiatives' ), 'add_new' => __( 'Add New', 'tica-initiatives' ), 'new_item' => __( 'New Initiative', 'tica-initiatives' ), 'edit_item' => __( 'Edit Initiative', 'tica-initiatives' ), 'update_item' => __( 'Update Initiative', 'tica-initiatives' ), 'view_item' => __( 'View Initiative', 'tica-initiatives' ), 'view_items' => __( 'View Initiatives', 'tica-initiatives' ), 'search_items' => __( 'Search Initiative', 'tica-initiatives' ), 'not_found' => __( 'Not found', 'tica-initiatives' ), 'not_found_in_trash' => __( 'Not found in Trash', 'tica-initiatives' ), 'featured_image' => __( 'Featured Image', 'tica-initiatives' ), 'set_featured_image' => __( 'Set featured image', 'tica-initiatives' ), 'remove_featured_image' => __( 'Remove featured image', 'tica-initiatives' ), 'use_featured_image' => __( 'Use as featured image', 'tica-initiatives' ), 'insert_into_item' => __( 'Insert into initiative', 'tica-initiatives' ), 'uploaded_to_this_item' => __( 'Uploaded to this initiative', 'tica-initiatives' ), 'items_list' => __( 'Initiatives list', 'tica-initiatives' ), 'items_list_navigation' => __( 'Initiatives list navigation', 'tica-initiatives' ), 'filter_items_list' => __( 'Filter initiatives list', 'tica-initiatives' ), ); $args = array( 'label' => __( 'Initiative', 'tica-initiatives' ), 'description' => __( 'Initiative Description', 'tica-initiatives' ), 'labels' => $labels, 'supports' => array( 'title', 'editor', 'excerpt', 'page-attributes', 'thumbnail' ), 'hierarchical' => false, 'public' => true, 'show_ui' => true, 'show_in_menu' => true, 'menu_position' => 30, 'menu_icon' => plugin_dir_url( __FILE__ ) . 'img/icon.png', 'show_in_admin_bar' => true, 'show_in_nav_menus' => true, 'can_export' => true, 'has_archive' => false, 'exclude_from_search' => true, 'publicly_queryable' => true, 'capability_type' => 'page', 'rewrite' => [ 'slug' => str_replace( '_', '-', TICA_Initiatives::POST_TYPE ) ] ); register_post_type( TICA_Initiatives::POST_TYPE, $args ); } public function save_post( $post_id, $post ) { if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) { return $post_id; } if ( ! is_a( $post, 'WP_Post' ) || ! has_shortcode( $post->post_content, TICA_Initiatives::SHORTCODE ) ) { return $post_id; } if ( ! current_user_can( 'edit_posts', $post_id ) && ! current_user_can( 'edit_pages', $post_id ) ) { return $post_id; } update_option( TICA_Initiatives::INITIATIVES_LIST_POST_ID_OPTION, $post_id ); return $post_id; } public function manage_posts_columns( $columns ) { $first_val = reset( $columns ); $first_key = key( $columns ); if ( 'cb' == $first_key ) { array_shift( $columns ); $columns = [ $first_key => $first_val, TICA_Initiatives::DEFAULT_ORDERBY => 'Order' ] + $columns; } else { $columns = [ TICA_Initiatives::DEFAULT_ORDERBY => 'Order' ] + $columns; } return $columns; } public function manage_sortable_columns( $columns ) { $columns[TICA_Initiatives::DEFAULT_ORDERBY] = [ TICA_Initiatives::DEFAULT_ORDERBY, true ]; return $columns; } public function manage_posts_custom_column( $column_name ) { global $post; esc_html_e( $post->{$column_name} ); } public function do_default_order() { if ( TICA_Initiatives::POST_TYPE == @$_REQUEST['post_type'] && empty( $_REQUEST['orderby'] ) ) { $url = get_admin_url( null, '/edit.php?' ); $url .= http_build_query( [ 'post_type' => TICA_Initiatives::POST_TYPE, 'orderby' => TICA_Initiatives::DEFAULT_ORDERBY, 'order' => TICA_Initiatives::DEFAULT_ORDER, ] ); wp_redirect( $url ); } } }