_shortcode, array( &$this, 'shortcode' ) ); } /** * Install method * * @since 1.0 * @return void */ public function install() { $this->_add_capability( $this->capability, 'administrator' ); } /** * Loads the plugin text domain for the plugin localization. Runs with * admin_init hook. * * @since 1.0 * @return void */ public function textdomain() { load_plugin_textdomain( $this->text_domain, false, '/apiki-wp-faq/assets/languages' ); } /** * Widget * * @since 1.0 * @return void */ public function widget() { require_once WP_PLUGIN_DIR . '/apiki-wp-faq/apiki-wp-faq-widget.php'; register_widget( 'Apiki_WP_FAQ_Widget' ); } /** * Create Apiki WP FAQ Post Type * * @since 1.0 * @return void */ public function create_post_type() { register_post_type( $this->post_type, array( 'labels' => array( 'name' => __( 'FAQ', $this->text_domain ), 'add_new' => __( 'Add New', $this->text_domain ), 'add_new_item' => __( 'Add New Question', $this->text_domain ), 'edit_item' => __( 'Edit Question', $this->text_domain ), 'new_item' => __( 'New Question', $this->text_domain ), 'view_item' => __( 'View Question', $this->text_domain ), 'search_items' => __( 'Search Questions', $this->text_domain ), 'not_found' => __( 'No Questions found', $this->text_domain ), 'not_found_in_trash' => __( 'No Questions found in trash', $this->text_domain ), 'all_items' => __( 'All Questions', $this->text_domain ) ), 'public' => true, 'show_ui' => true, 'supports' => array( 'title', 'editor', 'thumbnail' ), 'menu_icon' => WP_PLUGIN_URL . '/apiki-wp-faq/assets/images/apiki-wp-faq-16.png', 'menu_position' => null, 'rewrite' => array( 'slug' => 'faq' ) ) ); } /** * Create taxonomies for apiki wp faq post type * * @since 1.0 * @return void */ public function create_taxonomies() { register_taxonomy( $this->category_taxonomy, $this->post_type, array( 'hierarchical' => true, 'rewrite' => false ) ); } /** * Create sample FAQ * * @since 1.0.2 * @return int|WP_Error Question ID created or WP Error */ public function create_sample_faq() { $option_name = 'apiki_wp_faq_sample_faq'; $option_value = get_option( $option_name ); if( $option_value and $option_value == 'created' ) return; $faq = $this->get_faq(); if( !empty( $faq ) ) return; $faq_id = wp_insert_post( array( 'post_title' => __( 'Sample Question?', $this->text_domain ), 'post_content' => __( 'Here you can add an answer as well as add a content in posts and pages.', $this->text_domain ), 'post_status' => 'publish', 'post_type' => $this->post_type ) ); if( $faq_id and !is_wp_error( $faq_id ) ) update_option( $option_name, 'created' ); return $faq_id; } /** * Flush rules for faq/question when uses custom structure of permalinks * * @since 1.0.2 * @global object $wp_rewrite WordPress Rewrite Object * @return void */ public function flush_rules() { global $wp_rewrite; $wp_rewrite->flush_rules(); } /** * FAQ updated messages * * @global object $post * @global int $post_ID * @param array $messages * @return array */ public function updated_messages( $messages ) { global $post, $post_ID; $messages[$this->post_type] = array( 0 => '', 1 => sprintf( __( 'Question updated. View Question', $this->text_domain ), esc_url( get_permalink($post_ID) ) ), 2 => __( 'Custom field updated.', $this->text_domain ), 3 => __( 'Custom field deleted.', $this->text_domain ), 4 => __( 'Question updated.', $this->text_domain ), 5 => isset( $_GET['revision'] ) ? sprintf( __( 'Question restored to revision from %s', $this->text_domain ), wp_post_revision_title( (int)$_GET['revision'], false ) ) : false, 6 => sprintf( __( 'Question published. View Question', $this->text_domain ), esc_url( get_permalink($post_ID) ) ), 7 => __( 'Question saved.', $this->text_domain ), 8 => sprintf( __( 'Question submitted. Preview question', $this->text_domain ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) ), 9 => sprintf( __( 'Question scheduled for: %1$s. Preview question', $this->text_domain ), date_i18n( __( 'M j, Y @ G:i' ), strtotime( $post->post_date ) ), esc_url( get_permalink( $post_ID ) ) ), 10 => sprintf( __( 'Question draft updated. Preview question', $this->text_domain ), esc_url( add_query_arg( 'preview', 'true', get_permalink( $post_ID ) ) ) ), ); return $messages; } /** * Call the hooks for add the faq TinyMce button in the WordPress editor. * Runs with init hook. * * @since 1.0 * @return void */ public function tinymce_button() { if ( $this->_is_faq_admin_page() ) return; add_filter( 'mce_buttons', array( &$this, 'tinymce_register_button') , 5 ); add_filter( 'mce_external_plugins', array( &$this, 'tinymce_register_plugin'), 5 ); } /** * Register the button in the array of buttons in the tinymce bar. Runs with * mce_buttons hook. * * @since 1.0 * @param array $buttons The original array contains all buttons in tinymce * @return array Buttons */ public function tinymce_register_button( $buttons ) { array_push( $buttons, 'separator', 'apiki_wp_faq' ); return $buttons; } /** * Register the TinyMCE javascript plugin in the array os plugins. Runs with * mce_external_plugin hook. * * @since 1.0 * @param array $plugins The original array contains all plugins * @return Plugins */ public function tinymce_register_plugin( $plugins ) { $plugins['apiki_wp_faq'] = WP_PLUGIN_URL . '/apiki-wp-faq/assets/js/mce-plugin.js'; return $plugins; } /** * Enqueue javascript * * @since 1.0 * @return void */ public function javascript() { if( $this->_is_faq_admin_page() ) : wp_enqueue_script( 'apiki-wp-faq-script', WP_PLUGIN_URL . '/apiki-wp-faq/assets/js/script.js', array( 'jquery' ), filemtime( WP_PLUGIN_DIR . '/apiki-wp-faq/assets/js/script.js' ), true ); wp_localize_script( 'apiki-wp-faq-script', 'objectI18n', array( 'title_placeholder' => __( 'Enter question here', $this->text_domain ), 'title_table_column' => __( 'Question', $this->text_domain ) ) ); endif; } /** * Enqueue style * * @since 1.0 * @return void */ public function stylesheet() { if( $this->_is_faq_admin_page() ) wp_enqueue_style( 'apiki-wp-faq-stylesheet', WP_PLUGIN_URL . '/apiki-wp-faq/assets/css/style.css', null, filemtime( WP_PLUGIN_DIR . '/apiki-wp-faq/assets/css/style.css' ) ); } /** * Reads the shortcode and show FAQs * * @since 1.0 * @param array $args Params */ public function shortcode( $args ) { ob_start(); echo $this->display_faq($args); $output_string = ob_get_contents(); ob_end_clean(); return $output_string; } /** * Show FAQ * * @since 1.0 * @param array $args Options * @return void */ public function display_faq( $args = array() ) { $faq = $this->get_faq( $args ); $output = '