| @@ -52,8 +52,9 @@ | ||
| 52 | 52 | /** |
| 53 | 53 | * Initialize steps. |
| 54 | 54 | * |
| 55 | 55 | * @since 1.1.0 |
| 56 | + * @SuppressWarnings(PHPMD.NPathComplexity) | |
| 56 | 57 | */ |
| 57 | 58 | public function init() { |
| 58 | 59 | if ( empty( $this->funnel->current_step_data ) ) { |
| 59 | 60 | return; |
| @@ -65,8 +66,13 @@ | ||
| 65 | 66 | if ( is_user_logged_in() && current_user_can( 'administrator' ) ) { |
| 66 | 67 | return; |
| 67 | 68 | } |
| 68 | 69 | |
| 70 | + if ( ! empty( $this->funnel->funnel_id ) && 'publish' !== get_post_status( $this->funnel->funnel_id ) ) { | |
| 71 | + echo esc_html__( 'There is nothing to view here.', 'sellkit' ); | |
| 72 | + die(); | |
| 73 | + } | |
| 74 | + | |
| 69 | 75 | if ( ! empty( $this->funnel->current_step_data['status'] ) && 'publish' === $this->funnel->current_step_data['status'] ) { |
| 70 | 76 | return; |
| 71 | 77 | } |
| 72 | 78 | |
| @@ -88,13 +94,14 @@ | ||
| 88 | 94 | /** |
| 89 | 95 | * Create step instances. |
| 90 | 96 | * |
| 91 | 97 | * @since 1.1.0 |
| 98 | + * @param string $path Step path. | |
| 92 | 99 | * @return void |
| 93 | 100 | */ |
| 94 | - public function load_steps() { | |
| 95 | - $path = trailingslashit( Sellkit::$plugin_dir . 'includes/funnel/steps' ); | |
| 96 | - $file_paths = glob( $path . '*.php' ); | |
| 101 | + public function load_steps( $path = 'includes/funnel/steps' ) { | |
| 102 | + $real_path = trailingslashit( Sellkit::$plugin_dir . $path ); | |
| 103 | + $file_paths = glob( $real_path . '*.php' ); | |
| 97 | 104 | |
| 98 | 105 | if ( ! empty( $this->funnel->funnel_id ) ) { |
| 99 | 106 | $this->analytics_updater = new Data_Updater(); |
| 100 | 107 | |
| @@ -114,9 +121,9 @@ | ||
| 114 | 121 | $step_class = str_replace( '-', ' ', $file_name ); |
| 115 | 122 | $step_class = str_replace( ' ', '_', ucwords( $step_class ) ); |
| 116 | 123 | $step_class = "Sellkit\Funnel\Steps\\{$step_class}"; |
| 117 | 124 | |
| 118 | - if ( ! class_exists( $step_class ) ) { | |
| 125 | + if ( ! class_exists( $step_class ) || 'base-step' === $file_name ) { | |
| 119 | 126 | continue; |
| 120 | 127 | } |
| 121 | 128 | |
| 122 | 129 | $step = new $step_class(); |
| @@ -122,8 +129,13 @@ | ||
| 122 | 129 | $step = new $step_class(); |
| 123 | 130 | |
| 124 | 131 | self::$steps[ $file_name ] = $step; |
| 125 | 132 | } |
| 133 | + | |
| 134 | + // load children steps. | |
| 135 | + if ( 'includes/funnel/steps' === $path ) { | |
| 136 | + $this->load_steps( 'includes/funnel/steps/children' ); | |
| 137 | + } | |
| 126 | 138 | } |
| 127 | 139 | |
| 128 | 140 | /** |
| 129 | 141 | * Adds new visit log. |
| @@ -145,18 +157,16 @@ | ||
| 145 | 157 | if ( ! session_id() ) { |
| 146 | 158 | session_start(); |
| 147 | 159 | } |
| 148 | 160 | |
| 149 | - if ( array_key_exists( 'sellkit_viewed_funnels', $_SESSION ) && in_array( $this->funnel->funnel_id, $_SESSION['sellkit_viewed_funnels'] ) ) { // phpcs:ignore | |
| 161 | + $viewed_funnel_ids = isset( $_SESSION['sellkit_viewed_funnels'] ) ? array_map( 'absint', (array) $_SESSION['sellkit_viewed_funnels'] ) : []; | |
| 162 | + | |
| 163 | + if ( in_array( absint( $this->funnel->funnel_id ), $viewed_funnel_ids, true ) ) { | |
| 150 | 164 | return; |
| 151 | 165 | } |
| 152 | 166 | |
| 153 | - if ( empty( $_SESSION['sellkit_viewed_funnels'] ) ) { | |
| 154 | - $_SESSION['sellkit_viewed_funnels'] = []; | |
| 155 | - } | |
| 167 | + $_SESSION['sellkit_viewed_funnels'] = array_merge( $viewed_funnel_ids, [ absint( $this->funnel->funnel_id ) ] ); | |
| 156 | 168 | |
| 157 | - $_SESSION['sellkit_viewed_funnels'] = array_merge( $_SESSION['sellkit_viewed_funnels'], [ $this->funnel->funnel_id ] ); | |
| 158 | - | |
| 159 | 169 | add_action( 'init', function () { |
| 160 | 170 | $this->analytics_updater->add_new_visit( true ); |
| 161 | 171 | } ); |
| 162 | 172 | } |
| @@ -170,11 +180,21 @@ | ||
| 170 | 180 | public function add_start_and_finish_logs() { |
| 171 | 181 | $funnel = sellkit_funnel(); |
| 172 | 182 | $analytics_updater = new Data_Updater(); |
| 173 | 183 | |
| 184 | + if ( empty( $funnel->funnel_id ) && ! empty( Funnel_Homepage::$first_step ) ) { | |
| 185 | + $funnel = new Sellkit_Funnel( Funnel_Homepage::$first_step ); | |
| 186 | + } | |
| 187 | + | |
| 174 | 188 | $analytics_updater->set_funnel_id( $funnel->funnel_id ); |
| 189 | + $first_key = 0; | |
| 175 | 190 | |
| 176 | - if ( isset( $funnel->current_step_data['number'] ) && 0 === $funnel->current_step_data['number'] ) { | |
| 191 | + if ( isset( $funnel->funnel_id ) ) { | |
| 192 | + $nodes = get_post_meta( $funnel->funnel_id, 'nodes', true ); | |
| 193 | + $first_key = array_key_first( $nodes ); | |
| 194 | + } | |
| 195 | + | |
| 196 | + if ( isset( $funnel->current_step_data['number'] ) && $first_key === $funnel->current_step_data['number'] ) { | |
| 177 | 197 | $analytics_updater->add_new_start_log(); |
| 178 | 198 | } |
| 179 | 199 | |
| 180 | 200 | if ( empty( $funnel->next_step_data ) ) { |