Advertisement
brett

/public/class-simple-staff-list-public.php

Jan 29th, 2016
115
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
PHP 7.28 KB | None | 0 0
  1. <?php
  2.  
  3. /**
  4.  * The public-facing functionality of the plugin.
  5.  *
  6.  * @link       http://www.brettshumaker.com
  7.  * @since      1.17
  8.  *
  9.  * @package    Simple_Staff_List
  10.  * @subpackage Simple_Staff_List/public
  11.  */
  12.  
  13. /**
  14.  * The public-facing functionality of the plugin.
  15.  *
  16.  * Defines the plugin name, version, and two examples hooks for how to
  17.  * enqueue the admin-specific stylesheet and JavaScript.
  18.  *
  19.  * @package    Simple_Staff_List
  20.  * @subpackage Simple_Staff_List/public
  21.  * @author     Brett Shumaker <brettshumaker@gmail.com>
  22.  */
  23. class Simple_Staff_List_Public {
  24.  
  25.     /**
  26.      * The ID of this plugin.
  27.      *
  28.      * @since    1.17
  29.      * @access   private
  30.      * @var      string $plugin_name The ID of this plugin.
  31.      */
  32.     private $plugin_name;
  33.  
  34.     /**
  35.      * The version of this plugin.
  36.      *
  37.      * @since    1.17
  38.      * @access   private
  39.      * @var      string $version The current version of this plugin.
  40.      */
  41.     private $version;
  42.  
  43.     /**
  44.      * The default attributes for the shortcode
  45.      *
  46.      * @since  1.17
  47.      * @access  private
  48.      * @var
  49.      */
  50.     private $simple_staff_list_shortcode_atts;
  51.  
  52.     /**
  53.      * Initialize the class and set its properties.
  54.      *
  55.      * @since    1.17
  56.      * @param    string    $plugin_name       The name of the plugin.
  57.      * @param    string    $version    The version of this plugin.
  58.      */
  59.     public function __construct( $plugin_name, $version ) {
  60.  
  61.         $this->plugin_name = $plugin_name;
  62.         $this->version     = $version;
  63.         $this->simple_staff_list_shortcode_atts = array(
  64.             'single' => 'no',
  65.             'group' => '',
  66.             'wrap_class' => '',
  67.             'order' => 'ASC',
  68.             'image_size' => 'full',
  69.         );
  70.  
  71.         $this->staff_member_register_shortcodes();
  72.  
  73.     }
  74.  
  75.     /**
  76.      * Register the stylesheets for the public-facing side of the site.
  77.      *
  78.      * @since    1.17
  79.      */
  80.     public function enqueue_styles() {
  81.  
  82.         /**
  83.          * This function is provided for demonstration purposes only.
  84.          *
  85.          * An instance of this class should be passed to the run() function
  86.          * defined in Simple_Staff_List_Loader as all of the hooks are defined
  87.          * in that particular class.
  88.          *
  89.          * The Simple_Staff_List_Loader will then create the relationship
  90.          * between the defined hooks and the functions defined in this
  91.          * class.
  92.          */
  93.  
  94.         wp_enqueue_style( $this->plugin_name,
  95.             plugin_dir_url( __FILE__ ) . 'css/simple-staff-list-public.css',
  96.             array(),
  97.             $this->version,
  98.             'all' );
  99.  
  100.     }
  101.  
  102.     /**
  103.      * Register the stylesheets for the public-facing side of the site.
  104.      *
  105.      * @since    1.17
  106.      */
  107.     public function enqueue_scripts() {
  108.  
  109.         /**
  110.          * This function is provided for demonstration purposes only.
  111.          *
  112.          * An instance of this class should be passed to the run() function
  113.          * defined in Simple_Staff_List_Loader as all of the hooks are defined
  114.          * in that particular class.
  115.          *
  116.          * The Simple_Staff_List_Loader will then create the relationship
  117.          * between the defined hooks and the functions defined in this
  118.          * class.
  119.          */
  120.  
  121.         wp_enqueue_script( $this->plugin_name,
  122.             plugin_dir_url( __FILE__ ) . 'js/simple-staff-list-public.js',
  123.             array( 'jquery' ),
  124.             $this->version,
  125.             false );
  126.  
  127.     }
  128.  
  129.     /**
  130.      * Initialize staff member custom post type and taxonomies.
  131.      *
  132.      * @since 1.17
  133.      */
  134.     public function staff_member_init() {
  135.  
  136.         global $wp_version;
  137.  
  138.         // Get user options for post type labels
  139.         if ( ! get_option( '_staff_listing_custom_slug' ) ) {
  140.             $slug = get_option( '_staff_listing_default_slug' );
  141.         } else {
  142.             $slug = get_option( '_staff_listing_custom_slug' );
  143.         }
  144.         if ( ! get_option( '_staff_listing_custom_name_singular' ) ) {
  145.             $singular_name = get_option( '_staff_listing_default_name_singular' );
  146.         } else {
  147.             $singular_name = get_option( '_staff_listing_custom_name_singular' );
  148.         }
  149.         if ( ! get_option( '_staff_listing_custom_name_plural' ) ) {
  150.             $name = get_option( '_staff_listing_default_name_plural' );
  151.         } else {
  152.             $name = get_option( '_staff_listing_custom_name_plural' );
  153.         }
  154.  
  155.         // Set up post type options
  156.         $labels = array(
  157.             'name'                => $name,
  158.             'singular_name'       => $singular_name,
  159.             'add_new'             => _x( 'Add New', 'staff member', $this->plugin_name ),
  160.             'add_new_item'        => __( 'Add New Staff Member', $this->plugin_name ),
  161.             'edit_item'           => __( 'Edit Staff Member', $this->plugin_name ),
  162.             'new_item'            => __( 'New Staff Member', $this->plugin_name ),
  163.             'view_item'           => __( 'View Staff Member', $this->plugin_name ),
  164.             'search_items'        => __( 'Search Staff Members', $this->plugin_name ),
  165.             'exclude_from_search' => true,
  166.             'not_found'           => __( 'No staff members found', $this->plugin_name ),
  167.             'not_found_in_trash'  => __( 'No staff members found in Trash', $this->plugin_name ),
  168.             'parent_item_colon'   => '',
  169.             'all_items'           => __( 'All Staff Members', $this->plugin_name ),
  170.             'menu_name'           => __( 'Staff Members', $this->plugin_name ),
  171.         );
  172.  
  173.         $args = array(
  174.             'labels'             => $labels,
  175.             'public'             => true,
  176.             'publicly_queryable' => true,
  177.             'show_ui'            => true,
  178.             'show_in_menu'       => true,
  179.             'query_var'          => true,
  180.             'rewrite'            => true,
  181.             'capability_type'    => 'page',
  182.             'has_archive'        => true,
  183.             'hierarchical'       => false,
  184.             'menu_position'      => 100,
  185.             'rewrite'            => array( 'slug' => $slug, 'with_front' => false ),
  186.             'supports'           => array( 'title', 'thumbnail', 'excerpt' ),
  187.         );
  188.  
  189.         if ( version_compare( $wp_version, '3.8', '>=' ) ) {
  190.             $args['menu_icon'] = 'dashicons-groups';
  191.         }
  192.  
  193.         // Register post type
  194.         register_post_type( 'staff-member', $args );
  195.  
  196.         $group_labels = array(
  197.             'name'              => _x( 'Groups', 'taxonomy general name', $this->plugin_name ),
  198.             'singular_name'     => _x( 'Group', 'taxonomy singular name', $this->plugin_name ),
  199.             'search_items'      => __( 'Search Groups', $this->plugin_name ),
  200.             'all_items'         => __( 'All Groups', $this->plugin_name ),
  201.             'parent_item'       => __( 'Parent Group', $this->plugin_name ),
  202.             'parent_item_colon' => __( 'Parent Group:', $this->plugin_name ),
  203.             'edit_item'         => __( 'Edit Group', $this->plugin_name ),
  204.             'update_item'       => __( 'Update Group', $this->plugin_name ),
  205.             'add_new_item'      => __( 'Add New Group', $this->plugin_name ),
  206.             'new_item_name'     => __( 'New Group Name', $this->plugin_name ),
  207.         );
  208.         register_taxonomy( 'staff-member-group', array( 'staff-member' ), array(
  209.                 'hierarchical' => true,
  210.                 'labels' => $group_labels, /* NOTICE: Here is where the $labels variable is used */
  211.                 'show_ui' => true,
  212.                 'query_var' => true,
  213.                 'rewrite' => array( 'slug' => 'group' ),
  214.             ) );
  215.  
  216.     }
  217.  
  218.     /**
  219.      * Register plugin shortcode(s)
  220.      *
  221.      * @since 1.17
  222.      */
  223.     public function staff_member_register_shortcodes() {
  224.  
  225.         add_shortcode( 'simple-staff-list', array( $this, 'staff_member_simple_staff_list_shortcode_callback' ) );
  226.  
  227.     }
  228.  
  229.     /**
  230.      * Callback for [simple-staff-list]
  231.      *
  232.      * @since 1.17
  233.      */
  234.     public function staff_member_simple_staff_list_shortcode_callback( $atts = array() ) {
  235.  
  236.         global $sslp_sc_output;
  237.         $this->simple_staff_list_shortcode_atts = shortcode_atts( $this->simple_staff_list_shortcode_atts, $atts, 'simple-staff-list' );
  238.         include_once( 'partials/simple-staff-list-shortcode-display.php' );
  239.         return $sslp_sc_output;
  240.  
  241.     }
  242.  
  243. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement