*/ class Smart_Post_Show_Admin { /** * Script and style suffix * * @since 2.2.0 * @access protected * @var string */ protected $suffix; /** * Initialize the class and set its properties. * * @since 2.2.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->suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG || defined( 'WP_DEBUG' ) && WP_DEBUG ? '' : '.min'; $this->plugin_name = $plugin_name; $this->version = $version; // Autoload system. spl_autoload_register( array( $this, 'autoload' ) ); SPS_Metaboxes::preview_metabox( 'sp_pcp_display' ); SPS_Metaboxes::layout_metabox( 'sp_pcp_layouts' ); SPS_Metaboxes::option_metabox( 'sp_pcp_view_options' ); SPS_Metaboxes::shortcode_metabox( 'sp_pcp_display_shortcode' ); SPS_Settings::settings( 'sp_post_carousel_settings' ); SPS_Tools::tools( 'sp_post_carousel_tools' ); // Plugin action link Button. add_filter( 'plugin_action_links', array( $this, 'add_plugin_action_links' ), 10, 2 ); } /** * Add plugin action menu * * @param array $links The action link. * @param array $file The file link. * * @return array */ public function add_plugin_action_links( $links, $file ) { if ( SMART_POST_SHOW_BASENAME === $file ) { $new_links = array( sprintf( '%s', admin_url( 'post-new.php?post_type=sp_post_carousel' ), __( 'Add New', 'smart-post-show' ) ), sprintf( '%s', admin_url( 'edit.php?post_type=sp_post_carousel&page=pcp_settings' ), __( 'Settings', 'smart-post-show' ) ), ); $links['go_pro'] = sprintf( '%s', 'https://smartpostshow.com/', 'color:#1dab87;font-weight:bold', __( 'Go Premium!', 'smart-post-show' ) ); return array_merge( $new_links, $links ); } return $links; } /** * Add plugin row meta link * * @param [array] $plugin_meta Add plugin row meta link. * @param [url] $file plugin row meta link. * @return array */ public function after_pcp_row_meta( $plugin_meta, $file ) { if ( SMART_POST_SHOW_BASENAME == $file ) { $plugin_meta[] = '' . __( 'Live Demo', 'smart-post-show' ) . ''; $plugin_meta[] = '' . __( 'Documentation', 'smart-post-show' ) . ''; $plugin_meta[] = '' . __( 'Support', 'smart-post-show' ) . ''; } return $plugin_meta; } /** * Autoload class files on demand * * @param string $class requested class name. * @since 2.2.0 */ private function autoload( $class ) { $name = explode( '_', $class ); if ( isset( $name[1] ) ) { $class_name = strtolower( $name[1] ); $pcp_config_paths = array( 'views/', 'views/configs/settings/', 'views/configs/generator/' ); foreach ( $pcp_config_paths as $sp_ppc_path ) { $filename = plugin_dir_path( __FILE__ ) . '/' . $sp_ppc_path . 'class-sps-' . $class_name . '.php'; if ( file_exists( $filename ) ) { require_once $filename; } } } } /** * Register the stylesheets for the admin area. * * @since 2.2.0 */ public function enqueue_styles() { $current_screen = get_current_screen(); $the_current_post_type = $current_screen->post_type; if ( 'sp_post_carousel' === $the_current_post_type ) { wp_enqueue_style( 'pcp-font-awesome', SP_PC_URL . 'public/assets/css/font-awesome.min.css', array(), SP_PC_VERSION, 'all' ); wp_enqueue_style( 'pcp_swiper', SP_PC_URL . 'public/assets/css/swiper-bundle' . $this->suffix . '.css', array(), SP_PC_VERSION, 'all' ); wp_enqueue_style( 'pcp-style', SP_PC_URL . 'public/assets/css/style' . $this->suffix . '.css', array(), SP_PC_VERSION, 'all' ); } wp_enqueue_style( 'sp-' . SP_PC_PLUGIN_NAME, SP_PC_URL . 'admin/assets/css/post-carousel-admin' . $this->suffix . '.css', array(), SP_PC_VERSION, 'all' ); } /** * Register the JavaScript for the admin area. * * @since 2.2.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 Smart_Post_Show_Loader as all of the hooks are defined * in that particular class. * * The Smart_Post_Show_Loader will then create the relationship * between the defined hooks and the functions defined in this * class. */ $current_screen = get_current_screen(); $the_current_post_type = $current_screen->post_type; if ( 'sp_post_carousel' === $the_current_post_type ) { wp_enqueue_script( SP_PC_PLUGIN_NAME, SP_PC_URL . 'admin/assets/js/post-carousel-admin' . $this->suffix . '.js', array( 'jquery' ), SP_PC_VERSION, true ); wp_enqueue_script( 'pcp_swiper', SP_PC_URL . 'public/assets/js/swiper-bundle' . $this->suffix . '.js', array( 'jquery' ), SP_PC_VERSION, true ); wp_enqueue_script( 'pcp_script', SP_PC_URL . 'public/assets/js/scripts' . $this->suffix . '.js', array( 'jquery' ), SP_PC_VERSION, true ); } } /** * Add carousel admin columns. * * @since 2.2.0 * @return statement */ public function filter_carousel_admin_column() { $admin_columns['cb'] = ''; $admin_columns['title'] = __( 'Title', 'smart-post-show' ); $admin_columns['shortcode'] = __( 'Shortcode', 'smart-post-show' ); $admin_columns['pcp_layout'] = __( 'Layout', 'smart-post-show' ); $admin_columns['date'] = __( 'Date', 'smart-post-show' ); return $admin_columns; } /** * Display admin columns for the carousels. * * @param mix $column The columns. * @param string $post_id The post ID. * @return void */ public function display_carousel_admin_fields( $column, $post_id ) { $pcp_layouts = get_post_meta( $post_id, 'sp_pcp_layouts', true ); $carousels_types = isset( $pcp_layouts['pcp_layout_preset'] ) ? $pcp_layouts['pcp_layout_preset'] : ''; switch ( $column ) { case 'shortcode': ?>