constants(); register_activation_hook( __FILE__, array( $this, 'activation' ) ); register_deactivation_hook( __FILE__, array( $this, 'deactivation' ) ); add_action( 'init', array( $this, 'content_types' ) ); add_action( 'wp_enqueue_scripts', array( $this, 'enq_scripts' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'enq_admin_scripts' ) ); add_action( 'manage_posts_custom_column', array( $this, 'column_action' ) ); add_action( 'right_now_content_table_end', array( $this, 'right_now' ) ); add_action( 'wp_dashboard_setup', array( $this, 'dashboard_widget' ) ); add_action( 'init', 'arconix_faq_init_meta_boxes', 9999 ); add_filter( 'manage_faq_posts_columns', array( $this, 'columns_filter' ) ); add_filter( 'post_updated_messages', array( $this, 'messages' ) ); add_filter( 'cmb_meta_boxes', array( $this, 'metaboxes' ) ); add_shortcode( 'faq', array( $this, 'faq_shortcode' ) ); } /** * Defines constants used by the plugin. * * @since 1.2.0 */ function constants() { define( 'ACF_VERSION', '1.3.0' ); define( 'ACF_URL', trailingslashit( plugin_dir_url( __FILE__ ) ) ); define( 'ACF_INCLUDES_URL', trailingslashit( ACF_URL . 'includes' ) ); define( 'ACF_IMAGES_URL', trailingslashit( ACF_URL . 'images' ) ); define( 'ACF_CSS_URL', trailingslashit( ACF_INCLUDES_URL . 'css' ) ); define( 'ACF_DIR', trailingslashit( plugin_dir_path( __FILE__ ) ) ); define( 'ACF_INCLUDES_DIR', trailingslashit( ACF_DIR . 'includes' ) ); define( 'ACF_VIEWS_DIR', trailingslashit( ACF_INCLUDES_DIR . 'views' ) ); } /** * Runs on plugin activation * * @since 1.2.0 */ function activation() { $this->content_types(); flush_rewrite_rules(); } /** * Runs on plugin deactivation * * @since 1.2.0 */ function deactivation() { flush_rewrite_rules(); } /** * Register the post_type and taxonomy * * @since 1.2.0 */ function content_types() { $defaults = $this->defaults(); register_post_type( $defaults['post_type']['slug'], $defaults['post_type']['args'] ); register_taxonomy( $defaults['taxonomy']['slug'], $defaults['post_type']['slug'], $defaults['taxonomy']['args'] ); } /** * Define the defaults used in the registration of the post type and taxonomy * * @since 1.2.0 * @return array $defaults */ function defaults() { // Establishes plugin registration defaults for post type and taxonomy $defaults = array( 'post_type' => array( 'slug' => 'faq', 'args' => array( 'labels' => array( 'name' => __( 'FAQ', 'acf' ), 'singular_name' => __( 'FAQ', 'acf' ), 'add_new' => __( 'Add New', 'acf' ), 'add_new_item' => __( 'Add New Question', 'acf' ), 'edit' => __( 'Edit', 'acf' ), 'edit_item' => __( 'Edit Question', 'acf' ), 'new_item' => __( 'New Question', 'acf' ), 'view' => __( 'View FAQ', 'acf' ), 'view_item' => __( 'View Question', 'acf' ), 'search_items' => __( 'Search FAQ', 'acf' ), 'not_found' => __( 'No FAQs found', 'acf' ), 'not_found_in_trash' => __( 'No FAQs found in Trash', 'acf' ) ), 'public' => true, 'query_var' => true, 'menu_position' => 20, 'menu_icon' => ACF_IMAGES_URL . 'faq-16x16.png', 'has_archive' => false, 'supports' => array( 'title', 'editor', 'revisions' ), 'rewrite' => array( 'with_front' => false ) ) ), 'taxonomy' => array( 'slug' => 'group', 'args' => array( 'labels' => array( 'name' => __( 'Groups', 'acf' ), 'singular_name' => __( 'Group', 'acf' ), 'search_items' => __( 'Search Groups', 'acf' ), 'popular_items' => __( 'Popular Groups', 'acf' ), 'all_items' => __( 'All Groups', 'acf' ), 'parent_item' => null, 'parent_item_colon' => null, 'edit_item' => __( 'Edit Group' , 'acf' ), 'update_item' => __( 'Update Group', 'acf' ), 'add_new_item' => __( 'Add New Group', 'acf' ), 'new_item_name' => __( 'New Group Name', 'acf' ), 'separate_items_with_commas' => __( 'Separate groups with commas', 'acf' ), 'add_or_remove_items' => __( 'Add or remove groups', 'acf' ), 'choose_from_most_used' => __( 'Choose from the most used groups', 'acf' ), 'menu_name' => __( 'Groups', 'acf' ), ), 'hierarchical' => false, 'show_ui' => true, 'update_count_callback' => '_update_post_term_count', 'query_var' => true, 'rewrite' => array( 'with_front' => false ) ) ), 'query' => array( 'order' => 'ASC', 'orderby' => 'title', 'posts_per_page' => -1, 'nopaging' => true, 'group' => '', ) ); return apply_filters( 'arconix_faq_defaults', $defaults ); } /** * Create the post type metabox * * @param array $meta_boxes * @return array $meta_boxes * @since 1.2.0 */ function metaboxes( $meta_boxes ) { $metabox = array( 'id' => 'faq-setting', 'title' => __( 'FAQ Setting', 'acf' ), 'pages' => array( 'faq' ), 'context' => 'side', 'priority' => 'default', 'show_names' => false, 'fields' => array( array( 'id' => '_acf_rtt', 'name' => __( 'Show Return to Top', 'acf' ), 'desc' => __( 'Enable a "Return to Top" link on this FAQ', 'acf' ), 'type' => 'checkbox' ), array( 'id' => '_acf_open', 'name' => __( 'Load FAQ Open', 'acf' ), 'desc' => __( 'Load this FAQ in the open state (default is closed)', 'acf' ), 'type' => 'checkbox' ) ) ); $meta_boxes[] = $metabox; return $meta_boxes; } /** * Display FAQs * * @param type $atts * @since 0.9 * @version 1.2.0 */ function faq_shortcode( $atts, $content = null ) { // Set our JS to load wp_enqueue_script( 'arconix-faq-js' ); // Translate 'all' to nopaging = true ( for backward compatibility) if( isset( $atts['showposts'] ) ) { if( $atts['showposts'] != "all" and $atts['showposts'] > 0 ) { $atts['posts_per_page'] = $atts['showposts']; $atts['nopaging'] = false; } } return ARCONIX_FAQ::get_faq_data( $atts ); } /** * Get our FAQ data * * @param array $args * @param boolean $echo Echo or Return the data * @return mixed FAQ information for display * @since 1.2.0 */ function get_faq_data( $args, $echo = false ) { // Get our defaults $default_args = $this->defaults(); $defaults = $default_args['query']; // Merge incoming args with the function defaults $args = wp_parse_args( $args, $defaults ); // Container $return = ''; // Get the taxonomy terms assigned to all FAQs $terms = get_terms( $default_args['taxonomy']['slug'] ); // If there are any terms being used, loop through each one to output the relevant FAQ's, else just output all FAQs if( $terms ) { foreach( $terms as $term ) { // If a user sets a specific group in the params, that's the only one we care about $group = $args['group']; if( isset( $group ) and $group != '' and $term->slug != $group ) continue; // Set up our standard query args. $query_args = array( 'post_type' => $default_args['post_type']['slug'], 'order' => $args['order'], 'orderby' => $args['orderby'], 'posts_per_page' => $args['posts_per_page'], 'nopaging' => $args['nopaging'], 'tax_query' => array( array( 'taxonomy' => $default_args['taxonomy']['slug'], 'field' => 'slug', 'terms' => array( $term->slug ), 'operator' => 'IN' ) ) ); // New query just for the tax term we're looping through $q = new WP_Query( $query_args ); if( $q->have_posts() ) { $return .= '
' . $term->description . '
'; // Loop through the rest of the posts for the term while( $q->have_posts() ) : $q->the_post(); // Grab our metadata $rtt = get_post_meta( get_the_id(), '_acf_rtt', true ); $lo = get_post_meta( get_the_id(), '_acf_open', true ); // If Open on Load checkbox is true $lo == true ? $lo = ' faq-open' : $lo = ' faq-closed'; // Set up our anchor link $link = 'faq-' . sanitize_title( get_the_title() ); $return .= '