view/meta-flow-steps.php000066600000022777152141745040011304 0ustar00 __( 'Landing', 'cartflows' ), 'checkout' => __( 'Checkout (Woo)', 'cartflows' ), 'thankyou' => __( 'Thank You (Woo)', 'cartflows' ), 'upsell' => __( 'Upsell (Woo)', 'cartflows' ), 'downsell' => __( 'Downsell (Woo)', 'cartflows' ), 'optin' => __( 'Optin (Woo)', 'cartflows' ), ); ?>
$data ) { ?>

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.php000066600000002105152141745040014237 0ustar00include_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.php000066600000001062152141745040014707 0ustar00post_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.php000066600000006533152141745040015157 0ustar00post_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 = '
' . $before . $label . $after . '
'; } } return $output; } } /** * Kicking this off by calling 'get_instance()' method */ Cartflows_Flow_Shortcodes::get_instance(); classes/class-cartflows-flow-meta.php000066600000037014152141745040013726 0ustar00

$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 '
'; /* translators: %s: link */ echo '

' . sprintf( esc_html__( 'Upgrade to %1$sCartFlows Pro%2$s for Analytics feature', 'cartflows' ), '', '' ) . '

'; echo '

' . esc_html__( 'Get Pro', 'cartflows' ) . '

'; echo '
'; } /** * Settings meta box. * * @return void */ public function settings_meta_box() { if ( CARTFLOWS_FLOW_POST_TYPE === get_post_type() ) { /* No need of sandbox will delete it later */ add_meta_box( 'wcf-sandbox-settings', // Id. __( 'Flow Settings', 'cartflows' ), // Title. array( $this, 'sandbox_meta_box' ), // Callback. CARTFLOWS_FLOW_POST_TYPE, // Post_type. 'side', // Context. 'high' // Priority. ); do_action( 'cartflows_add_flow_metabox' ); } } /** * Metabox Markup * * @return void */ public function markup_meta_box() { global $post; wp_nonce_field( 'save-nonce-flow-meta', 'nonce-flow-meta' ); // Get defaults. $meta = self::get_current_post_meta( $post->ID ); /** * Get options */ $updated_data = array( 'steps' => $meta['wcf-steps']['default'], ); do_action( 'wcf_flow_settings_markup_before', $meta ); $this->page_header_tab( $updated_data ); do_action( 'wcf_flow_settings_markup_after', $meta ); } /** * Metabox Markup * * @param object $post Post object. * @return void */ public function sandbox_meta_box( $post ) { // Get defaults. $meta = self::get_current_post_meta( $post->ID ); /** * Get options */ foreach ( $meta as $key => $value ) { $updated_data[ $key ] = $meta[ $key ]['default']; } do_action( 'wcf_flow_sandbox_markup_before', $meta ); $this->sandbox_markup( $updated_data ); do_action( 'wcf_flow_sandbox_markup_after', $meta ); } /** * Page Header Tabs * * @param array $options Post meta. * @return void */ public function page_header_tab( $options ) { include_once CARTFLOWS_FLOW_DIR . 'view/meta-flow-steps.php'; } /** * Sandbox Markup * * @param array $options Post meta. * @return void */ public function sandbox_markup( $options ) { ?>
meta->get_checkbox_field( array( 'name' => 'wcf-testing', 'value' => $options['wcf-testing'], 'after' => esc_html__( 'Enable Test Mode', 'cartflows' ), ) ); echo wcf()->meta->get_description_field( array( 'name' => 'wcf-testing-note', 'content' => esc_html__( 'If you are using WooCommerce plugin then test mode will add random products in your flow, so you can preview it easily while testing.', 'cartflows' ), ) ); ?>
options->get_flow_fields( $post_id ); } return self::$meta_option; } /** * Get metabox options * * @param int $post_id post ID. * @return array */ public static function get_current_post_meta( $post_id ) { $stored = get_post_meta( $post_id ); $default_meta = self::get_meta_option( $post_id ); // Set stored and override defaults. foreach ( $stored as $key => $value ) { if ( array_key_exists( $key, $default_meta ) ) { self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? maybe_unserialize( $stored[ $key ][0] ) : ''; } else { self::$meta_option[ $key ]['default'] = ( isset( $stored[ $key ][0] ) ) ? $stored[ $key ][0] : ''; } } return self::get_meta_option( $post_id ); } /** * Metabox Save * * @param number $post_id Post ID. * @return void */ public function save_meta_box( $post_id ) { // Checks save status. $is_autosave = wp_is_post_autosave( $post_id ); $is_revision = wp_is_post_revision( $post_id ); $is_valid_nonce = ( isset( $_POST['nonce-flow-meta'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['nonce-flow-meta'] ) ), 'save-nonce-flow-meta' ) ) ? true : false; // Exits script depending on save status. if ( $is_autosave || $is_revision || ! $is_valid_nonce ) { return; } wcf()->options->save_flow_fields( $post_id ); } /** * Localize variables in admin * * @param array $vars variables. */ public function localize_vars( $vars ) { $ajax_actions = array( 'wcf_setup_default_steps', 'wcf_add_flow_step', 'wcf_delete_flow_step', 'wcf_reorder_flow_steps', ); foreach ( $ajax_actions as $action ) { $vars[ $action . '_nonce' ] = wp_create_nonce( str_replace( '_', '-', $action ) ); } return $vars; } /** * Add New Step Button * * @return string */ public function add_add_new_step_button() { $add_new_btn_markup = ''; $add_new_btn_markup .= "
"; $add_new_btn_markup .= "'; $add_new_btn_markup .= '
'; return $add_new_btn_markup; } } /** * Kicking this off by calling 'get_instance()' method */ Cartflows_Flow_Meta::get_instance(); classes/class-cartflows-step-post-type.php000066600000031031152141745040014741 0ustar00post_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: /** * 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 ) ) { $file = $page; } 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', array( $this, 'body_class' ) ); return $file; } else { echo $file; } } return $template; } /** * Body classes. * * @since 1.0.0 * @param array $classes Body classes. * @return array */ public function body_class( $classes = array() ) { $classes = array_merge( $classes, $this->body_classes ); return $classes; } /** * Create custom post type */ public 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' ), ); $permalink_settings = Cartflows_Helper::get_permalink_settings(); $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, ); if ( isset( $permalink_settings['permalink_structure'] ) && ! empty( $permalink_settings['permalink_structure'] ) ) { $args['rewrite'] = array( 'slug' => $permalink_settings['permalink_structure'], 'with_front' => false, ); } elseif ( isset( $permalink_settings['permalink'] ) && ! empty( $permalink_settings['permalink'] ) ) { $args['rewrite'] = array( 'slug' => $permalink_settings['permalink'], 'with_front' => false, ); } register_post_type( CARTFLOWS_STEP_POST_TYPE, $args ); // Step Type. $args = array( 'label' => __( 'Step Type', 'cartflows' ), 'public' => false, 'rewrite' => false, 'hierarchical' => false, ); register_taxonomy( CARTFLOWS_TAXONOMY_STEP_TYPE, CARTFLOWS_STEP_POST_TYPE, $args ); // Step Flow. $args = array( 'label' => __( 'Step Flow', 'cartflows' ), 'public' => false, 'rewrite' => false, 'hierarchical' => false, ); register_taxonomy( CARTFLOWS_TAXONOMY_STEP_FLOW, CARTFLOWS_STEP_POST_TYPE, $args ); if ( is_admin() ) { /** * Register 'Elementor' & 'Beaver Builder' site types. * * @see self::add_terms(); */ $taxonomy = CARTFLOWS_TAXONOMY_STEP_TYPE; $terms = array( array( 'name' => __( 'Landing', 'cartflows' ), 'slug' => 'landing', 'args' => array( 'slug' => 'landing', ), ), array( 'name' => __( 'Optin (Woo)', 'cartflows' ), 'slug' => 'optin', 'args' => array( 'slug' => 'optin', ), ), array( 'name' => __( 'Checkout (Woo)', 'cartflows' ), 'slug' => 'checkout', 'args' => array( 'slug' => 'checkout', ), ), array( 'name' => __( 'Thank You (Woo)', 'cartflows' ), 'slug' => 'thankyou', 'args' => array( 'slug' => 'thankyou', ), ), array( 'name' => __( 'Upsell (Woo)', 'cartflows' ), 'slug' => 'upsell', 'args' => array( 'slug' => 'upsell', ), ), array( 'name' => __( 'Downsell (Woo)', 'cartflows' ), 'slug' => 'downsell', 'args' => array( 'slug' => 'downsell', ), ), ); $this->add_terms( $taxonomy, $terms ); } } /** * Add WordPress templates. * * Adds Cartflows templates to steps * * @since 1.0.0 * @access public */ 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. */ public function add_page_templates( $page_templates, $wp_theme, $post ) { $page_templates = array( 'cartflows-default' => _x( 'CartFlows — Boxed', 'cartflows' ), 'cartflows-canvas' => _x( 'Template for Page Builders', 'cartflows' ), ); return $page_templates; } /** * Query fixe throwing error on 404 page due our post type changes. * We are setting post_type as empty array to fix the issue. * Ther error was throwing due to redirect_canonical function * This fix is apply for 404 page only */ public function query_fix() { global $wp_query; if ( $wp_query->is_404() ) { $wp_query->set( 'post_type', array() ); } } /** * 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 */ public 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, true ) ) { 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. */ public 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, //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; } /** * Add Terms for Taxonomy. * * => Example. * * $taxonomy = '{taxonomy}'; * $terms = array( * array( * 'name' => 'Landing', * 'slug' => 'landing', * ), * array( * 'name' => 'Checkout', * 'slug' => 'checkout', * ), * ); * * self::add_terms( $taxonomy, $terms ); * * @since 1.0.0 * @param string $taxonomy Taxonomy Name. * @param array $terms Terms list. * @return void */ public function add_terms( $taxonomy = '', $terms = array() ) { foreach ( $terms as $key => $term ) { $term_exist = term_exists( $term['slug'], $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 { $term['args'] = array( $term['slug'] ); wp_insert_term( $term['name'], $taxonomy, $term['args'] ); } } } } } /** * Kicking this off by calling 'get_instance()' method */ Cartflows_Step_Post_Type::get_instance(); class-cartflows-flow.php000066600000001554152141745040011345 0ustar00 class="no-js"> >
>
class="no-js"> >
>