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_URL . 'images/faq-16x16.png', 'has_archive' => true, 'supports' => array( 'title', 'editor', 'revisions' ), 'rewrite' => array( 'slug' => 'faqs', 'with_front' => false ) ) ); register_post_type( 'faq', $args ); } /** * Create the Custom Taxonomy * * @since 1.1 */ function create_taxonomy() { $args = apply_filters( 'arconix_faq_taxonomy_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( 'slug' => 'group' ) ) ); register_taxonomy( 'group', 'faq', $args ); } /** Modify updated messages on post type save */ function updated_messages( $messages ) { global $post, $post_ID; $messages['faq'] = array( 0 => '', // Unused. Messages start at index 1. 1 => sprintf( __('FAQ updated. View staff'), esc_url( get_permalink($post_ID) ) ), 2 => __('Custom field updated.'), 3 => __('Custom field deleted.'), 4 => __('FAQ updated.'), /* translators: %s: date and time of the revision */ 5 => isset($_GET['revision']) ? sprintf( __('FAQ restored to revision from %s'), wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, 6 => sprintf( __('FAQ published. View FAQ'), esc_url( get_permalink($post_ID) ) ), 7 => __('FAQ saved.'), 8 => sprintf( __('FAQ submitted. Preview FAQ'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ), 9 => sprintf( __('FAQ scheduled for: %1$s. Preview FAQ'), // translators: Publish box date format, see http://php.net/date date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink($post_ID) ) ), 10 => sprintf( __('FAQ draft updated. Preview FAQ'), esc_url( add_query_arg( 'preview', 'true', get_permalink($post_ID) ) ) ), ); return $messages; } /** * Add the post-type icon to the admin screen */ function post_type_admin_image() { printf( '', ACF_URL . 'images/faq-32x32.png' ); } /** * Choose the specific columns we want to display * * @param array $columns * @return string * @since 0.9 */ function columns_filter ( $columns ) { $columns = array ( "cb" => "", "title" => "FAQ Title", "faq_content" => "Details", 'faq_groups' => __( 'Groups', 'acf' ), "date" => "Date" ); return $columns; } /** * Filter the data that shows up in the columns we defined above * * @global type $post * @param type $column * @since 0.9 */ function column_data( $column ) { global $post; switch( $column ) { case "faq_content": the_excerpt(); break; case "faq_groups": echo get_the_term_list( $post->ID, 'group', '', ', ', '' ); break; default: break; } } /** * Register the javascript */ function register_script() { if( file_exists( get_stylesheet_directory() . "/arconix-faq.js" ) ) { wp_register_script( 'arconix-faq-js', get_stylesheet_directory_uri() . '/arconix-faq.js', array( 'jquery' ), ACF_VERSION, true ); } elseif( file_exists( get_template_directory() . "/arconix-faq.js" ) ) { wp_register_script( 'arconix-faq-js', get_template_directory_uri() . '/arconix-faq.js', array( 'jquery' ), ACF_VERSION, true ); } else { wp_register_script( 'arconix-faq-js', ACF_URL . 'includes/faq.js', array( 'jquery' ), ACF_VERSION, true ); } } /** * Load the javascript on a page where the FAQ shortcode is used * @return type */ function print_script() { if( ! self::$load_js ) return; wp_print_scripts( 'arconix-faq-js' ); } /** * Load the plugin's stylesheet */ function enqueue_css() { if( file_exists( get_stylesheet_directory() . "/arconix-faq.css" ) ) { wp_enqueue_style( 'arconix-faq', get_stylesheet_directory_uri() . '/arconix-faq.css', array(), ACF_VERSION ); } elseif( file_exists( get_template_directory() . "/arconix-faq.css" ) ) { wp_enqueue_style( 'arconix-faq', get_template_directory_uri() . '/arconix-faq.css', array(), ACF_VERSION ); } else { wp_enqueue_style( 'arconix-faq', ACF_URL . 'includes/faq.css', array(), ACF_VERSION ); } } /** * Display FAQs * * @param type $atts * @param type $content * @since 0.9 * @version 1.1 */ function faq_shortcode( $atts ) { // Set the js flag self::$load_js = true; $defaults = apply_filters( 'arconix_faq_shortcode_query_args', array( 'showposts' => 'all', 'order' => 'ASC', 'orderby' => 'title' ) ); extract( shortcode_atts( $defaults, $atts ) ); /** Translate 'all' to -1 for query terms */ if( $showposts == "all" ) $showposts = "-1"; $return = ''; $terms = get_terms( 'group' ); if( $terms ) { foreach( $terms as $term ) { /** Build my query showing only faq's from the taxonomy term we're looping through */ $faq_query = new WP_Query( array( 'post_type' => 'faq', 'order' => $order, 'orderby' => $orderby, 'posts_per_page' => $showposts, 'tax_query' => array( array( 'taxonomy' => 'group', 'field' => 'slug', 'terms' => array( $term->slug ), 'operator' => 'IN' ) ) ) ); if ( $faq_query->have_posts() ) { $return .= '
' . $term->description . '
'; /** Loop through the rest of the posts for the term */ while ( $faq_query->have_posts() ) : $faq_query->the_post(); $return .= '