view/meta-flow-steps.php 0000666 00000022777 15214174504 0011304 0 ustar 00 __( 'Landing', 'cartflows' ), 'checkout' => __( 'Checkout (Woo)', 'cartflows' ), 'thankyou' => __( 'Thank You (Woo)', 'cartflows' ), 'upsell' => __( 'Upsell (Woo)', 'cartflows' ), 'downsell' => __( 'Downsell (Woo)', 'cartflows' ), 'optin' => __( 'Optin (Woo)', 'cartflows' ), ); ?>
post_type ) && CARTFLOWS_STEP_POST_TYPE === $post->post_type ) { $flow_id = get_post_meta( $post->ID, 'wcf-flow-id', true ); $flow_title = get_the_title( $flow_id ); $post_states['cartflows_step'] = '( ' . __( 'Flow: ', 'cartflows' ) . $flow_id . ' | ' . __( 'Name: ', 'cartflows' ) . $flow_title . ')'; } return $post_states; } /** * Display slugdiv. * * @param array $hidden metaboxes. * @param obj $screen screen. * @return array */ public function display_flow_slug_meta_box( $hidden, $screen ) { $post_type = $screen->id; if ( ! empty( $post_type ) && CARTFLOWS_FLOW_POST_TYPE === $post_type ) { $pos = array_search( 'slugdiv', $hidden, true ); unset( $hidden[ $pos ] ); } return $hidden; } /** * Create custom post type */ public function flow_post_type() { $labels = array( 'name' => esc_html_x( 'Flows', 'flow general name', 'cartflows' ), 'singular_name' => esc_html_x( 'Flow', 'flow singular name', 'cartflows' ), 'search_items' => esc_html__( 'Search Flows', 'cartflows' ), 'all_items' => esc_html__( 'All Flows', 'cartflows' ), 'edit_item' => esc_html__( 'Edit Flow', 'cartflows' ), 'view_item' => esc_html__( 'View Flow', 'cartflows' ), 'add_new' => esc_html__( 'Add New', 'cartflows' ), 'update_item' => esc_html__( 'Update Flow', 'cartflows' ), 'add_new_item' => esc_html__( 'Add New', 'cartflows' ), 'new_item_name' => esc_html__( 'New Flow Name', 'cartflows' ), ); $args = array( 'labels' => $labels, 'show_in_menu' => false, 'public' => false, // it's not public, not own permalink. 'publicly_queryable' => true, // you should be able to query it. 'show_ui' => true, 'query_var' => true, 'can_export' => true, 'show_in_admin_bar' => true, 'exclude_from_search' => true, 'has_archive' => false, // it shouldn't have archive page. 'rewrite' => false, // it shouldn't have rewrite rules. 'supports' => array( 'title', 'thumbnail', 'slug' ), 'capability_type' => 'post', ); if ( ! _is_cartflows_pro() ) { $flow_posts = get_posts( array( 'posts_per_page' => 4, 'post_type' => CARTFLOWS_FLOW_POST_TYPE, 'post_status' => array( 'publish', 'pending', 'draft', 'future', 'private', 'inherit', 'trash' ), ) ); if ( is_array( $flow_posts ) ) { $flow_count = count( $flow_posts ); if ( $flow_count > 3 || 3 === $flow_count ) { $args['capabilities'] = array( 'create_posts' => 'do_not_allow', ); $args['map_meta_cap'] = true; // Add new notice button. add_action( 'admin_print_footer_scripts', array( $this, 'add_new_notice_button' ) ); // Add the notice popup HTML to admin footer. add_action( 'admin_footer', array( $this, 'upgrade_to_pro_notice_popup' ) ); } } } register_post_type( CARTFLOWS_FLOW_POST_TYPE, $args ); } /** * Show custom add new button. */ public function add_new_notice_button() { $screen = get_current_screen(); if ( is_object( $screen ) && CARTFLOWS_FLOW_POST_TYPE === $screen->post_type && 'edit-cartflows_flow' === $screen->id ) { ?> get_first_step_url( $post ); if ( $first_step && isset( $actions['view'] ) ) { $actions['view'] = '' . __( 'View', 'cartflows' ) . ''; } return $actions; } /** * Returns previous post link * * @param string $prev_link previous link. * @param array $post post data. * @return string */ public function preview_post_link( $prev_link, $post ) { if ( $this->is_flow_post_type( $post ) ) { $first_step = $this->get_first_step_url( $post ); if ( $first_step ) { return $first_step; } return ''; } return $prev_link; } /** * Check if post type is flow * * @param array $post post data. * @return bool */ public function is_flow_post_type( $post ) { if ( isset( $post ) && CARTFLOWS_FLOW_POST_TYPE === $post->post_type ) { return true; } return false; } /** * Redirect to first step * * @return void */ public function redirect_to_step() { global $post; $first_step = $this->get_first_step_url( $post ); if ( $first_step ) { wp_safe_redirect( $first_step ); die; } } /** * Return first step URL * * @param array $post post data. * @return bool */ public function get_first_step_url( $post ) { if ( $this->is_flow_post_type( $post ) ) { $flow_id = $post->ID; $title = $post->post_title; $steps = get_post_meta( $flow_id, 'wcf-steps', true ); if ( is_array( $steps ) && ! empty( $steps ) && isset( $steps[0]['id'] ) ) { return get_permalink( $steps[0]['id'] ); } } return false; } /** * Register the admin menu for Custom Layouts * * @since 1.0.0 * Moved the menu under Appearance -> Custom Layouts public function register_admin_menu() { add_submenu_page( CARTFLOWS_SLUG, __( 'Flows', 'wcf' ), __( 'Flows', 'wcf' ), 'edit_pages', 'edit.php?post_type=' . CARTFLOWS_FLOW_POST_TYPE ); } */ public function register_as_submenu() { global $submenu; $submenu[ CARTFLOWS_SLUG ][0] = array( //phpcs:ignore __( 'Flows', 'cartflows' ), 'edit_pages', 'edit.php?post_type=' . CARTFLOWS_FLOW_POST_TYPE, ); } /** * Add Update messages for any custom post type * * @param array $messages Array of default messages. */ public function custom_post_type_post_update_messages( $messages ) { $custom_post_type = get_post_type( get_the_ID() ); if ( CARTFLOWS_FLOW_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, //phpcs:ignore /* 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; } } /** * Kicking this off by calling 'get_instance()' method */ Cartflows_Flow_Post_Type::get_instance(); classes/class-cartflows-flow-loader.php 0000666 00000002105 15214174504 0014237 0 ustar 00 include_files(); } /** * Load classes. * * @since 1.0.0 * * @return void */ public function include_files() { require_once CARTFLOWS_FLOW_DIR . 'classes/class-cartflows-flow-post-type.php'; require_once CARTFLOWS_FLOW_DIR . 'classes/class-cartflows-step-post-type.php'; require_once CARTFLOWS_FLOW_DIR . 'classes/class-cartflows-step-post-meta.php'; require_once CARTFLOWS_FLOW_DIR . 'classes/class-cartflows-flow-shortcodes.php'; require_once CARTFLOWS_FLOW_DIR . 'classes/class-cartflows-permalink.php'; } } /** * Kicking this off by calling 'get_instance()' method */ Cartflows_Flow_Loader::get_instance(); classes/class-cartflows-step-post-meta.php 0000666 00000001062 15214174504 0014707 0 ustar 00 post_type ) && CARTFLOWS_STEP_POST_TYPE == $post->post_type ) { $flow_id = get_post_meta( $post->ID, 'wcf-flow-id', true ); $flow_name = get_post_field( 'post_name', $flow_id ); $cf_permalink = Cartflows_Helper::get_permalink_settings(); if ( isset( $cf_permalink['permalink_structure'] ) && ! empty( $cf_permalink['permalink_structure'] ) ) { $search = array( 'cartflows_flow', '%flowname%', 'cartflows_step' ); $replace = array( $cf_permalink['permalink_flow_base'], $flow_name, $cf_permalink['permalink'] ); $post_link = str_replace( $search, $replace, $post_link ); } else { // If elementor page preview, return post link as it is. if ( isset( $_REQUEST['elementor-preview'] ) ) { //phpcs:ignore return $post_link; } $structure = get_option( 'permalink_structure' ); if ( '/%postname%/' === $structure ) { $post_link = str_replace( '/' . $post->post_type . '/', '/', $post_link ); } } } return $post_link; } /** * Reqrite rules for acrtflows step. */ public function rewrite_step_rule() { $cf_permalink = Cartflows_Helper::get_permalink_settings(); if ( isset( $cf_permalink['permalink_structure'] ) ) { switch ( $cf_permalink['permalink_structure'] ) { case '/cartflows_flow/%flowname%/cartflows_step': add_rewrite_rule( '^' . $cf_permalink['permalink_flow_base'] . '/([^/]*)/' . $cf_permalink['permalink'] . '/([^\/]*)/?', 'index.php?cartflows_step=$matches[2]', 'top' ); break; case '/cartflows_flow/%flowname%': add_rewrite_rule( '^' . $cf_permalink['permalink_flow_base'] . '/([^/]*)/([^/]*)/?', 'index.php?cartflows_step=$matches[2]', 'top' ); break; case '/%flowname%/cartflows_step': add_rewrite_rule( '([^/]*)/' . $cf_permalink['permalink'] . '/([^\/]*)/?', 'index.php?cartflows_step=$matches[2]', 'top' ); break; default: break; } } } /** * 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. */ public 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['thrive-variations'] ) && ! 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 ) ); } } } /** * Kicking this off by calling 'get_instance()' method */ Cartflows_Permalink::get_instance(); classes/class-cartflows-flow-shortcodes.php 0000666 00000006533 15214174504 0015157 0 ustar 00 post_type ) { $navigation = false; $step_id = intval( $post->ID ); $flow_id = get_post_meta( $step_id, 'wcf-flow-id', true ); if ( ! $flow_id ) { return $output; } $steps = get_post_meta( $flow_id, 'wcf-steps', true ); if ( ! is_array( $steps ) || ( is_array( $steps ) && empty( $steps ) ) ) { return $output; } foreach ( $steps as $i => $step ) { if ( intval( $step['id'] ) === $step_id ) { $next_i = $i + 1; if ( isset( $steps[ $next_i ] ) ) { $navigation = $steps[ $next_i ]; } break; } } if ( $navigation && is_array( $navigation ) ) { $output = get_permalink( $navigation['id'] ); } } return $output; } /** * Navigation shortcode callback * * @param array $atts attributes for shortcode. * @return string */ public function navigation_shortcode( $atts ) { $atts = shortcode_atts( array( 'label' => '', 'icon' => '', 'icon_position' => '', ), $atts ); global $post; $output = ''; if ( $post && CARTFLOWS_STEP_POST_TYPE === $post->post_type ) { $navigation = false; $step_id = intval( $post->ID ); $flow_id = get_post_meta( $step_id, 'wcf-flow-id', true ); if ( ! $flow_id ) { return $output; } $steps = get_post_meta( $flow_id, 'wcf-steps', true ); if ( ! is_array( $steps ) || ( is_array( $steps ) && empty( $steps ) ) ) { return $output; } foreach ( $steps as $i => $step ) { if ( intval( $step['id'] ) === $step_id ) { $next_i = $i + 1; if ( isset( $steps[ $next_i ] ) ) { $navigation = $steps[ $next_i ]; } break; } } if ( $navigation && is_array( $navigation ) ) { $label = ( '' != $atts['label'] ) ? $atts['label'] : __( 'Next Step', 'cartflows' ); $before = ''; $after = ''; if ( '' != $atts['icon'] ) { if ( '' != $atts['icon_position'] ) { if ( 'before' == $atts['icon_position'] ) { $before = ''; } else { $after = ''; } } } $output = ''; } } return $output; } } /** * Kicking this off by calling 'get_instance()' method */ Cartflows_Flow_Shortcodes::get_instance(); classes/class-cartflows-flow-meta.php 0000666 00000037014 15214174504 0013726 0 ustar 00 $step ) { wp_delete_post( $step['id'], true ); } } $term_data = term_exists( 'flow-' . $pid, CARTFLOWS_TAXONOMY_STEP_FLOW ); if ( is_array( $term_data ) ) { wp_delete_term( $term_data['term_id'], CARTFLOWS_TAXONOMY_STEP_FLOW ); } } } /** * Trash steps data after trashing flow. * * @since 1.0.0 * @param int $pid post id. * * @return void */ public function step_post_trash_sync( $pid ) { global $post_type; if ( CARTFLOWS_FLOW_POST_TYPE === $post_type ) { $steps = get_post_meta( $pid, 'wcf-steps', true ); if ( $steps && is_array( $steps ) ) { foreach ( $steps as $i => $step ) { wp_trash_post( $step['id'] ); } } } } /** * Untrash steps data after restoring flow. * * @since 1.0.0 * @param int $pid post id. * * @return void */ public function step_post_untrash_sync( $pid ) { global $post_type; if ( CARTFLOWS_FLOW_POST_TYPE === $post_type ) { $steps = get_post_meta( $pid, 'wcf-steps', true ); if ( $steps && is_array( $steps ) ) { foreach ( $steps as $i => $step ) { wp_untrash_post( $step['id'] ); } } } } /** * Create step for given flow. * * @param int $flow_id flow ID. * @param int $step_type step type. * @param int $step_title step title. * @since 1.0.0 * * @return int */ public function create_step( $flow_id, $step_type, $step_title ) { $new_step_id = wp_insert_post( array( 'post_type' => CARTFLOWS_STEP_POST_TYPE, 'post_title' => $step_title, 'post_status' => 'publish', ) ); if ( $new_step_id ) { $flow_steps = get_post_meta( $flow_id, 'wcf-steps', true ); if ( ! is_array( $flow_steps ) ) { $flow_steps = array(); } $flow_steps[] = array( 'id' => $new_step_id, 'title' => $step_title, 'type' => $step_type, ); // insert post meta. update_post_meta( $new_step_id, 'wcf-flow-id', $flow_id ); update_post_meta( $new_step_id, 'wcf-step-type', $step_type ); wp_set_object_terms( $new_step_id, $step_type, CARTFLOWS_TAXONOMY_STEP_TYPE ); wp_set_object_terms( $new_step_id, 'flow-' . $flow_id, CARTFLOWS_TAXONOMY_STEP_FLOW ); } update_post_meta( $flow_id, 'wcf-steps', $flow_steps ); return $new_step_id; } /** * Delete step for flow * * @since 1.0.0 * * @return void */ public function cartflows_delete_flow_step() { if ( ! current_user_can( 'manage_options' ) ) { return; } check_ajax_referer( 'wcf-delete-flow-step', 'security' ); if ( isset( $_POST['post_id'] ) && isset( $_POST['step_id'] ) ) { $flow_id = intval( $_POST['post_id'] ); $step_id = intval( $_POST['step_id'] ); } $result = array( 'status' => false, /* translators: %s flow id */ 'text' => sprintf( __( 'Step not deleted for flow - %s', 'cartflows' ), $flow_id ), ); if ( ! $flow_id || ! $step_id ) { wp_send_json( $result ); } wp_delete_post( $step_id, true ); $flow_steps = get_post_meta( $flow_id, 'wcf-steps', true ); if ( ! is_array( $flow_steps ) ) { wp_send_json( $result ); } foreach ( $flow_steps as $index => $data ) { if ( intval( $data['id'] ) === $step_id ) { unset( $flow_steps[ $index ] ); break; } } /* Set index order properly */ $flow_steps = array_merge( $flow_steps ); update_post_meta( $flow_id, 'wcf-steps', $flow_steps ); $result = array( 'status' => true, /* translators: %s flow id */ 'text' => sprintf( __( 'Step deleted for flow - %s', 'cartflows' ), $flow_id ), ); wp_send_json( $result ); } /** * Reorder step flow * * @since 1.0.0 * * @return void */ public function cartflows_reorder_flow_steps() { if ( ! current_user_can( 'manage_options' ) ) { return; } check_ajax_referer( 'wcf-reorder-flow-steps', 'security' ); if ( isset( $_POST['post_id'] ) && isset( $_POST['step_ids'] ) ) { $flow_id = intval( $_POST['post_id'] ); $step_ids = array_map( 'intval', $_POST['step_ids'] ); } $result = array( 'status' => false, /* translators: %s flow id */ 'text' => sprintf( __( 'Steps not sorted for flow - %s', 'cartflows' ), $flow_id ), ); if ( ! $flow_id || ! is_array( $step_ids ) ) { wp_send_json( $result ); } $new_flow_steps = array(); foreach ( $step_ids as $index => $step_id ) { $new_flow_steps[] = array( 'id' => intval( $step_id ), 'title' => get_the_title( $step_id ), 'type' => get_post_meta( $step_id, 'wcf-step-type', true ), ); } update_post_meta( $flow_id, 'wcf-steps', $new_flow_steps ); $result = array( 'status' => true, /* translators: %s flow id */ 'text' => sprintf( __( 'Steps sorted for flow - %s', 'cartflows' ), $flow_id ), ); wp_send_json( $result ); } /** * Load admin scripts * * @since 1.0.0 * * @return void */ public function admin_scripts() { global $pagenow; global $post; $screen = get_current_screen(); if ( ( 'post-new.php' == $pagenow || 'post.php' == $pagenow ) && CARTFLOWS_FLOW_POST_TYPE == $screen->post_type ) { wp_enqueue_script( 'wcf-flow-meta', CARTFLOWS_URL . 'admin/assets/js/flow-admin-edit.js', array( 'jquery', 'jquery-ui-sortable' ), CARTFLOWS_VER, true ); wp_enqueue_style( 'wcf-flow-meta', CARTFLOWS_URL . 'admin/assets/css/flow-admin-edit.css', '', CARTFLOWS_VER ); wp_style_add_data( 'wcf-flow-meta', 'rtl', 'replace' ); $localize = array( 'ajax_url' => admin_url( 'admin-ajax.php' ), ); wp_localize_script( 'jquery', 'cartflows', apply_filters( 'wcf_js_localize', $localize ) ); } } /** * Initialize meta box * * @since 1.0.0 * * @return void */ public function init_metabox() { /** * Fires after the title field. * * @param WP_Post $post Post object. */ add_action( 'add_meta_boxes', array( $this, 'settings_meta_box' ) ); add_action( 'edit_form_after_title', array( $this, 'setup_meta_box' ) ); add_action( 'save_post', array( $this, 'save_meta_box' ) ); } /** * Is first time import? * * @param integer $post_id post ID. * @return bool */ public function is_flow_imported( $post_id = 0 ) { if ( 0 === $post_id ) { $post_id = get_the_ID(); } $steps = get_post_meta( $post_id, 'wcf-steps', true ); $choice = get_post_meta( $post_id, 'wcf-flow-choise', true ); if ( empty( $steps ) && 'import' === $choice ) { return true; } return false; } /** * Setup meta box. * * @return void */ public function setup_meta_box() { if ( ! Cartflows_Admin::is_flow_edit_admin() ) { return; } /** * Adding Add new step button to the top*/ echo $this->add_add_new_step_button(); $this->markup_meta_box(); $this->add_upgrade_to_pro_metabox(); } /** * Add metabox when cartflows pro is not enabled. */ public function add_upgrade_to_pro_metabox() { if ( ! _is_cartflows_pro() ) { add_meta_box( 'wcf-upgrade-pro', __( 'Analytics', 'cartflows' ), array( $this, 'upgrade_to_pro' ), CARTFLOWS_FLOW_POST_TYPE, 'side', 'high' ); } } /** * Show Upgrade To Pro markup. */ public function upgrade_to_pro() { echo '' . sprintf( esc_html__( 'Upgrade to %1$sCartFlows Pro%2$s for Analytics feature', 'cartflows' ), '', '' ) . '
'; echo ''; echo '