PluginProbe ʕ •ᴥ•ʔ
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress / 5.6.11
Appointment Booking Plugin – LatePoint | Calendar & Scheduling for WordPress v5.6.11
5.6.11 5.6.10 5.6.9 5.6.8 5.6.7 5.6.6 5.6.5 5.6.4 5.6.3 5.6.2 5.6.1 5.6.0 5.5.2 5.5.1 5.5.0 5.4.2 trunk 5.1.0 5.1.1 5.1.2 5.1.3 5.1.4 5.1.5 5.1.6 5.1.7 5.1.8 5.1.9 5.1.91 5.1.92 5.1.93 5.1.94 5.2.0 5.2.1 5.2.10 5.2.11 5.2.2 5.2.3 5.2.4 5.2.5 5.2.6 5.2.7 5.2.8 5.2.9 5.3.0 5.3.1 5.3.2 5.4.0 5.4.1
latepoint / lib / helpers / pages_helper.php
latepoint / lib / helpers Last commit date
activities_helper.php 5 months ago admin_nudges_helper.php 1 month ago agent_helper.php 5 months ago analytics_helper.php 1 month ago auth_helper.php 2 months ago blocks_helper.php 2 months ago booking_helper.php 4 days ago bricks_helper.php 5 months ago bundles_helper.php 2 months ago calendar_helper.php 1 month ago carts_helper.php 5 months ago connector_helper.php 5 months ago csv_helper.php 5 months ago customer_helper.php 3 months ago customer_import_helper.php 3 months ago database_helper.php 1 month ago debug_helper.php 5 months ago defaults_helper.php 5 months ago elementor_helper.php 5 months ago email_helper.php 5 months ago encrypt_helper.php 5 months ago events_helper.php 5 months ago form_helper.php 4 days ago icalendar_helper.php 5 months ago image_helper.php 5 months ago invoices_helper.php 1 month ago license_helper.php 5 months ago location_helper.php 5 months ago marketing_systems_helper.php 5 months ago meeting_systems_helper.php 5 months ago menu_helper.php 2 months ago meta_helper.php 5 months ago migrations_helper.php 5 months ago money_helper.php 5 months ago notifications_helper.php 5 months ago nps_survey_helper.php 5 months ago order_intent_helper.php 4 months ago orders_helper.php 2 months ago otp_helper.php 5 months ago pages_helper.php 4 days ago params_helper.php 5 months ago payments_helper.php 2 months ago paypal_connect_helper.php 1 month ago plugin_version_update_helper.php 4 months ago price_breakdown_helper.php 5 months ago process_jobs_helper.php 1 month ago processes_helper.php 4 days ago razorpay_connect_helper.php 1 month ago replacer_helper.php 4 days ago resource_helper.php 2 months ago roles_helper.php 1 month ago router_helper.php 5 months ago service_helper.php 5 months ago sessions_helper.php 5 months ago settings_helper.php 2 months ago short_links_systems_helper.php 5 months ago shortcodes_helper.php 2 months ago sms_helper.php 5 months ago steps_helper.php 4 days ago stripe_connect_helper.php 2 months ago styles_helper.php 5 months ago support_topics_helper.php 5 months ago time_helper.php 4 days ago timeline_helper.php 4 months ago transaction_helper.php 3 months ago transaction_intent_helper.php 5 months ago util_helper.php 1 month ago version_specific_updates_helper.php 1 month ago whatsapp_helper.php 3 months ago work_periods_helper.php 4 days ago wp_datetime.php 5 months ago wp_user_helper.php 5 months ago
pages_helper.php
134 lines
1 <?php
2
3 class OsPagesHelper {
4
5 /**
6 * Create Latepoint predefined pages
7 * @return void
8 */
9 public static function create_predefined_pages(): void {
10 $pages = [
11 'customer-cabinet' => array(
12 'slug' => _x( 'customer-cabinet', 'Customer cabinet', 'latepoint' ),
13 'title' => _x( 'Customer Cabinet', 'Customer cabinet', 'latepoint' ),
14 'content' => '<!-- wp:latepoint/customer-dashboard --><div class="wp-block-latepoint-customer-dashboard">Customer Dashboard</div><!-- /wp:latepoint/customer-dashboard -->',
15 'settings' => [ 'page_url_customer_dashboard', 'page_url_customer_login' ],
16 ),
17 ];
18 foreach ( $pages as $key => $page_settings ) {
19 $option = 'latepoint_page_' . $key;
20 $page_id = self::create_page( $page_settings, $option );
21 if ( $page_id ) {
22 update_option( $option, $page_id );
23 }
24 }
25 }
26
27
28 /**
29 * @param array $page_settings
30 * @param string $option
31 *
32 * @return int|WP_Error
33 */
34 public static function create_page( array $page_settings, string $option = '' ) {
35 $option_page_id = get_option( $option );
36
37 if ( $option_page_id > 0 ) {
38 $page_object = get_post( $option_page_id );
39 if ( $page_object && 'page' === $page_object->post_type && ! in_array( $page_object->post_status, array( 'pending', 'trash', 'future', 'auto-draft' ), true ) ) {
40 return $page_object->ID;
41 }
42 }
43
44 $page = self::get_page_by_slug( $page_settings['slug'] );
45
46 if ( $page ) {
47 return $page;
48 }
49
50 $page_data = array(
51 'post_status' => 'publish',
52 'post_type' => 'page',
53 'post_author' => 1,
54 'post_name' => esc_sql( $page_settings['slug'] ),
55 'post_title' => $page_settings['title'],
56 'post_content' => $page_settings['content'],
57 'comment_status' => 'closed',
58 );
59 $new_page_id = wp_insert_post( $page_data );
60
61 # if page is created - Set Page URLs in settings
62 if ( $new_page_id && count( $page_settings['settings'] ) ) {
63 self::save_default_pages_settings( $page_settings['settings'], "/{$page_settings['slug']}" );
64 }
65
66 return $new_page_id;
67 }
68
69 /**
70 * Add states for Latepoint Pages
71 * @param $post_states
72 * @param $page
73 *
74 * @return array
75 */
76 public static function add_display_post_states( $post_states, $page ): array {
77 if ( get_option( 'latepoint_page_customer-cabinet' ) == $page->ID ) {
78 $post_states['latepoint_customer_cabinet'] = 'Latepoint Customer Cabinet';
79 }
80 return $post_states;
81 }
82
83 /**
84 * Check if the current request is the Customer Dashboard or Customer Login page
85 * @return bool
86 */
87 public static function is_customer_dashboard_or_login_page(): bool {
88 if ( ! is_singular() ) {
89 return false;
90 }
91
92 $current_page_id = get_the_ID();
93
94 // Match the configured pages by path, so pages built with Elementor/Bricks are covered too.
95 $current_path = get_page_uri( $current_page_id );
96
97 if ( $current_path ) {
98 $dashboard_path = trim( (string) OsSettingsHelper::get_customer_dashboard_url( false ), '/' );
99 $login_path = trim( (string) OsSettingsHelper::get_customer_login_url( false ), '/' );
100
101 if ( $current_path === $dashboard_path || $current_path === $login_path ) {
102 return true;
103 }
104 }
105
106 return false;
107 }
108
109 /**
110 * Get page ID by slug with status published
111 * @param $slug
112 * @return string|null
113 */
114 public static function get_page_by_slug( $slug ) {
115 global $wpdb;
116 return $wpdb->get_var( $wpdb->prepare( "SELECT ID FROM $wpdb->posts WHERE post_type='page' AND post_status NOT IN ( 'pending', 'trash', 'future', 'auto-draft' ) AND post_name = %s LIMIT 1;", $slug ) );
117 }
118
119 /**
120 * save default pages settings
121 * @param array $settings
122 * @param $value
123 *
124 * @return void
125 */
126 private static function save_default_pages_settings( array $settings, $value ): void {
127 foreach ( $settings as $name ) {
128 if ( ! OsSettingsHelper::get_settings_value( $name ) ) {
129 OsSettingsHelper::save_setting_by_name( $name, $value );
130 }
131 }
132 }
133 }
134