PluginProbe
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce / 1.0.4
CartFlows – Funnel Builder & Checkout Plugin for WooCommerce v1.0.4
3.3.0 3.2.1 3.2.0 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.1 trunk 1.0.4 1.1.0 1.1.0.1 1.1.1 1.1.10 1.1.11 1.1.12 1.1.13 1.1.14 1.1.15 1.1.16 1.1.17 1.1.18 1.1.19 1.1.2 All 162 releases
cartflows / modules / landing / classes / class-cartflows-landing-markup.php

class-cartflows-landing-markup.php in CartFlows – Funnel Builder & Checkout Plugin for WooCommerce 1.0.4, at modules/landing/classes/class-cartflows-landing-markup.php

134 lines 2.7 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Markup
4 *
5 * @package CartFlows
6 */
7
8 /**
9 * Checkout Markup
10 *
11 * @since 1.0.0
12 */
13 class Cartflows_Landing_Markup {
14
15
16 /**
17 * Member Variable
18 *
19 * @var object instance
20 */
21 private static $instance;
22
23 /**
24 * Initiator
25 */
26 public static function get_instance() {
27 if ( ! isset( self::$instance ) ) {
28 self::$instance = new self;
29 }
30 return self::$instance;
31 }
32
33 /**
34 * Constructor
35 */
36 public function __construct() {
37
38 add_action( 'pre_get_posts', array( $this, 'pre_get_posts' ) );
39 add_action( 'template_redirect', array( $this, 'template_redirect' ) );
40
41 if ( is_admin() ) {
42 add_filter( 'wp_dropdown_pages', array( $this, 'wp_dropdown_pages' ) );
43 }
44 }
45
46 /**
47 * Add landing pages in WordPress reading section.
48 *
49 * @param array $output output.
50 */
51 function wp_dropdown_pages( $output ) {
52
53 global $pagenow;
54
55 if ( ( 'options-reading.php' === $pagenow || 'customize.php' === $pagenow ) && preg_match( '#page_on_front#', $output ) ) {
56
57 $args = array(
58 'post_type' => CARTFLOWS_STEP_POST_TYPE,
59 'meta_query' => array(
60 array(
61 'key' => 'wcf-step-type',
62 'value' => 'landing',
63 ),
64 ),
65 );
66
67 $landing_pages = get_posts( $args );
68
69 if ( is_array( $landing_pages ) && ! empty( $landing_pages ) ) {
70
71 $cartflows_custom_option = '';
72
73 $front_page_id = get_option( 'page_on_front' );
74
75 foreach ( $landing_pages as $key => $landing_page ) {
76
77 $selected = selected( $front_page_id, $landing_page->ID, false );
78
79 $cartflows_custom_option .= "<option value=\"{$landing_page->ID}\"{$selected}>{$landing_page->post_title} (CartFlows)</option>";
80 }
81
82 $cartflows_custom_option .= '</select>';
83
84 $output = str_replace( '</select>', $cartflows_custom_option, $output );
85 }
86 }
87
88 return $output;
89 }
90
91 /**
92 * Set post query.
93 *
94 * @param string $query post query.
95 */
96 function pre_get_posts( $query ) {
97
98 if ( $query->is_main_query() && ! ( defined( 'DOING_AJAX' ) && DOING_AJAX ) ) {
99
100 $post_type = $query->get( 'post_type' );
101
102 $page_id = $query->get( 'page_id' );
103
104 if ( empty( $post_type ) && ! empty( $page_id ) ) {
105 $query->set( 'post_type', get_post_type( $page_id ) );
106 }
107 }
108 }
109
110 /**
111 * Redirect to homepage if landing page set as home page.
112 */
113 function template_redirect() {
114
115 $compatibiliy = Cartflows_Compatibility::get_instance();
116
117 // Do not redirect for page builder preview.
118 if ( $compatibiliy->is_page_builder_preview() ) {
119 return;
120 }
121
122 global $post;
123
124 if ( is_singular() && ! is_front_page() && get_option( 'page_on_front' ) == $post->ID ) {
125 wp_safe_redirect( site_url(), 301 );
126 }
127 }
128 }
129
130 /**
131 * Kicking this off by calling 'get_instance()' method
132 */
133 Cartflows_Landing_Markup::get_instance();
134