post_type ) { /** * Remove Next/Prev Navigation * add_filter('next_post_link', '__return_empty_string'); * add_filter('previous_post_link', '__return_empty_string'); * * $page = locate_template( array( 'page.php' ) ); * * if ( ! empty( $page ) ) { * return $page; * } */ /* Remove Next / Previous Rel Link */ remove_action( 'wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0 ); add_filter( 'next_post_rel_link', '__return_empty_string' ); add_filter( 'previous_post_rel_link', '__return_empty_string' ); $page_template = get_post_meta( _get_wcf_step_id(), '_wp_page_template', true ); $page_template = apply_filters( 'cartflows_page_template', $page_template ); $file = ''; switch ( $page_template ) { case 'cartflows-default': $file = CARTFLOWS_FLOW_DIR . 'templates/template-default.php'; $this->body_classes[] = $page_template; break; case 'cartflows-canvas': $file = CARTFLOWS_FLOW_DIR . 'templates/template-canvas.php'; $this->body_classes[] = $page_template; break; default: $file = CARTFLOWS_FLOW_DIR . 'templates/template-default.php'; $this->body_classes[] = 'cartflows-default'; break; } // Just to be safe, we check if the file exist first. if ( file_exists( $file ) ) { /* Add Body Class */ add_filter( 'body_class', [ $this, 'body_class' ] ); return $file; } else { echo $file; } } return $template; } /** * Body classes. * * @since 1.0.0 * @param array $classes Body classes. * @return array */ function body_class( $classes = [] ) { $classes = array_merge( $classes, $this->body_classes ); return $classes; } /** * Create custom post type */ function step_post_type() { $labels = array( 'name' => esc_html_x( 'Steps', 'flow step general name', 'cartflows' ), 'singular_name' => esc_html_x( 'Step', 'flow step singular name', 'cartflows' ), 'search_items' => esc_html__( 'Search Steps', 'cartflows' ), 'all_items' => esc_html__( 'All Steps', 'cartflows' ), 'edit_item' => esc_html__( 'Edit Step', 'cartflows' ), 'view_item' => esc_html__( 'View Step', 'cartflows' ), 'add_new' => esc_html__( 'Add New', 'cartflows' ), 'update_item' => esc_html__( 'Update Step', 'cartflows' ), 'add_new_item' => esc_html__( 'Add New', 'cartflows' ), 'new_item_name' => esc_html__( 'New Step Name', 'cartflows' ), ); $args = array( 'labels' => $labels, 'public' => true, 'query_var' => true, 'can_export' => true, 'exclude_from_search' => true, 'show_ui' => true, 'show_in_menu' => false, 'show_in_admin_bar' => true, 'supports' => array( 'title', 'editor', 'elementor', 'revisions' ), 'capability_type' => 'post', 'capabilities' => array( 'create_posts' => 'do_not_allow', // Prior to Wordpress 4.5, this was false. ), 'map_meta_cap' => true, ); register_post_type( CARTFLOWS_STEP_POST_TYPE, $args ); $args = array( 'label' => __( 'Step Type', 'cartflows' ), 'public' => false, 'rewrite' => false, 'hierarchical' => false, ); register_taxonomy( CARTFLOWS_TAXONOMY_STEP_TYPE, CARTFLOWS_STEP_POST_TYPE, $args ); $args = array( 'label' => __( 'Step Flow', 'cartflows' ), 'public' => false, 'rewrite' => false, 'hierarchical' => false, ); register_taxonomy( CARTFLOWS_TAXONOMY_STEP_FLOW, CARTFLOWS_STEP_POST_TYPE, $args ); /** * Register 'Elementor' & 'Beaver Builder' site types. * * @see self::add_terms(); */ $taxonomy = CARTFLOWS_TAXONOMY_STEP_TYPE; $terms = array( array( 'name' => __( 'Landing', 'cartflows' ), 'args' => array( 'slug' => 'landing', ), ), array( 'name' => __( 'Checkout', 'cartflows' ), 'args' => array( 'slug' => 'checkout', ), ), array( 'name' => __( 'Thank You', 'cartflows' ), 'args' => array( 'slug' => 'thankyou', ), ), array( 'name' => __( 'Upsell', 'cartflows' ), 'args' => array( 'slug' => 'upsell', ), ), array( 'name' => __( 'Downsell', 'cartflows' ), 'args' => array( 'slug' => 'downsell', ), ), ); $this->add_terms( $taxonomy, $terms ); } /** * Add WordPress templates. * * Adds Cartflows templates to steps * * @since 1.0.0 * @access public */ function add_wp_templates_support() { add_filter( 'theme_' . CARTFLOWS_STEP_POST_TYPE . '_templates', array( $this, 'add_page_templates' ), 99, 4 ); } /** * Add page templates. * * @since 1.0.0 * @access public * * @param array $page_templates Array of page templates. * * @param object $wp_theme wp theme. * @param object $post post. * * @return array Page templates. */ function add_page_templates( $page_templates, $wp_theme, $post ) { $page_templates = array( 'cartflows-canvas' => _x( 'Template for Page Builders', 'cartflows' ), ); return $page_templates; } /** * Have WordPress match postname to any of our public post types. * All of our public post types can have /post-name/ as the slug, so they need to be unique across all posts. * By default, WordPress only accounts for posts and pages where the slug is /post-name/. * * @param string $query query statement. */ function add_cpt_post_names_to_main_query( $query ) { // Bail if this is not the main query. if ( ! $query->is_main_query() ) { return; } // Bail if this query doesn't match our very specific rewrite rule. if ( ! isset( $query->query['page'] ) || 2 !== count( $query->query ) ) { return; } // Bail if we're not querying based on the post name. if ( empty( $query->query['name'] ) ) { return; } // Add cartflows step post type to existing post type array. if ( isset( $query->query_vars['post_type'] ) && is_array( $query->query_vars['post_type'] ) ) { $post_types = $query->query_vars['post_type']; $post_types[] = CARTFLOWS_STEP_POST_TYPE; $query->set( 'post_type', $post_types ); } else { // Add CPT to the list of post types WP will include when it queries based on the post name. $query->set( 'post_type', array( 'post', 'page', CARTFLOWS_STEP_POST_TYPE ) ); } } /** * Modify permalink * * @param string $post_link post link. * @param array $post post data. * @param string $leavename leave name. * @return string */ function post_type_permalinks( $post_link, $post, $leavename ) { // If elementor page preview, return post link as it is. if ( isset( $_REQUEST['elementor-preview'] ) ) { return $post_link; } $structure = get_option( 'permalink_structure' ); if ( '/%postname%/' === $structure ) { if ( isset( $post->post_type ) && CARTFLOWS_STEP_POST_TYPE == $post->post_type ) { $post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link ); } } return $post_link; } /** * Prevent slug duplicated * * @param string $slug post slug. * @param int $post_ID post id. * @param string $post_status post status. * @param string $post_type post type. * @param int $post_parent post parent id. * @param string $original_slug original slug. * @return string */ function prevent_slug_duplicates( $slug, $post_ID, $post_status, $post_type, $post_parent, $original_slug ) { $check_post_types = array( 'post', 'page', CARTFLOWS_STEP_POST_TYPE, ); if ( ! in_array( $post_type, $check_post_types ) ) { return $slug; } if ( CARTFLOWS_STEP_POST_TYPE == $post_type ) { // Saving a post, check for duplicates in POST or PAGE post types. $post_match = get_page_by_path( $slug, 'OBJECT', 'post' ); $page_match = get_page_by_path( $slug, 'OBJECT', 'page' ); if ( $post_match || $page_match ) { $slug .= '-2'; } } else { // Saving a POST or PAGE, check for duplicates in CARTFLOWS_STEP_POST_TYPE post type. $custom_post_type_match = get_page_by_path( $slug, 'OBJECT', CARTFLOWS_STEP_POST_TYPE ); if ( $custom_post_type_match ) { $slug .= '-2'; } } return $slug; } /** * Add Update messages for any custom post type * * @param array $messages Array of default messages. */ function post_update_messages( $messages ) { $custom_post_type = get_post_type( get_the_ID() ); if ( CARTFLOWS_STEP_POST_TYPE == $custom_post_type ) { $obj = get_post_type_object( $custom_post_type ); $singular_name = $obj->labels->singular_name; $messages[ $custom_post_type ] = array( 0 => '', // Unused. Messages start at index 1. /* translators: %s: singular custom post type name */ 1 => sprintf( __( '%s updated.', 'cartflows' ), $singular_name ), /* translators: %s: singular custom post type name */ 2 => sprintf( __( 'Custom %s updated.', 'cartflows' ), $singular_name ), /* translators: %s: singular custom post type name */ 3 => sprintf( __( 'Custom %s deleted.', 'cartflows' ), $singular_name ), /* translators: %s: singular custom post type name */ 4 => sprintf( __( '%s updated.', 'cartflows' ), $singular_name ), /* translators: %1$s: singular custom post type name ,%2$s: date and time of the revision */ 5 => isset( $_GET['revision'] ) ? sprintf( __( '%1$s restored to revision from %2$s', 'cartflows' ), $singular_name, wp_post_revision_title( (int) $_GET['revision'], false ) ) : false, /* translators: %s: singular custom post type name */ 6 => sprintf( __( '%s published.', 'cartflows' ), $singular_name ), /* translators: %s: singular custom post type name */ 7 => sprintf( __( '%s saved.', 'cartflows' ), $singular_name ), /* translators: %s: singular custom post type name */ 8 => sprintf( __( '%s submitted.', 'cartflows' ), $singular_name ), /* translators: %s: singular custom post type name */ 9 => sprintf( __( '%s scheduled for.', 'cartflows' ), $singular_name ), /* translators: %s: singular custom post type name */ 10 => sprintf( __( '%s draft updated.', 'cartflows' ), $singular_name ), ); } return $messages; } /** * Add Terms for Taxonomy. * * => Example. * * $taxonomy = '{taxonomy}'; * $terms = array( * array( * 'name' => 'Free', * ), * array( * 'name' => 'Premium', * ), * ); * * self::add_terms( $taxonomy, $terms ); * * @since 1.0.0 * @param string $taxonomy Taxonomy Name. * @param array $terms Terms list. * @return void */ function add_terms( $taxonomy = '', $terms = array() ) { foreach ( $terms as $key => $term ) { $term_exist = term_exists( $term['name'], $taxonomy ); if ( empty( $term_exist ) ) { /** * Add additional args if passed from request. * * @see https://codex.wordpress.org/Function_Reference/wp_insert_term */ if ( array_key_exists( 'args', $term ) ) { wp_insert_term( $term['name'], $taxonomy, $term['args'] ); } else { wp_insert_term( $term['name'], $taxonomy ); } } } } } /** * Kicking this off by calling 'get_instance()' method */ Cartflows_Step_Post_Type::get_instance();