activities_helper.php
3 months ago
agent_helper.php
3 months ago
analytics_helper.php
4 months ago
auth_helper.php
3 months ago
blocks_helper.php
3 months ago
booking_helper.php
3 months ago
bricks_helper.php
3 months ago
bundles_helper.php
3 months ago
calendar_helper.php
3 months ago
carts_helper.php
3 months ago
connector_helper.php
3 months ago
csv_helper.php
3 months ago
customer_helper.php
3 months ago
customer_import_helper.php
3 months ago
database_helper.php
3 months ago
debug_helper.php
3 months ago
defaults_helper.php
3 months ago
elementor_helper.php
3 months ago
email_helper.php
3 months ago
encrypt_helper.php
3 months ago
events_helper.php
3 months ago
form_helper.php
3 months ago
icalendar_helper.php
3 months ago
image_helper.php
3 months ago
invoices_helper.php
3 months ago
license_helper.php
3 months ago
location_helper.php
3 months ago
marketing_systems_helper.php
3 months ago
meeting_systems_helper.php
3 months ago
menu_helper.php
3 months ago
meta_helper.php
3 months ago
migrations_helper.php
3 months ago
money_helper.php
3 months ago
notifications_helper.php
3 months ago
nps_survey_helper.php
3 months ago
order_intent_helper.php
3 months ago
orders_helper.php
3 months ago
otp_helper.php
3 months ago
pages_helper.php
3 months ago
params_helper.php
3 months ago
payments_helper.php
3 months ago
price_breakdown_helper.php
3 months ago
process_jobs_helper.php
3 months ago
processes_helper.php
3 months ago
replacer_helper.php
3 months ago
resource_helper.php
3 months ago
roles_helper.php
3 months ago
router_helper.php
3 months ago
service_helper.php
3 months ago
sessions_helper.php
3 months ago
settings_helper.php
3 months ago
short_links_systems_helper.php
3 months ago
shortcodes_helper.php
3 months ago
sms_helper.php
3 months ago
steps_helper.php
3 months ago
stripe_connect_helper.php
3 months ago
styles_helper.php
3 months ago
support_topics_helper.php
3 months ago
time_helper.php
3 months ago
timeline_helper.php
3 months ago
transaction_helper.php
3 months ago
transaction_intent_helper.php
3 months ago
util_helper.php
3 months ago
version_specific_updates_helper.php
3 months ago
whatsapp_helper.php
3 months ago
work_periods_helper.php
3 months ago
wp_datetime.php
3 months ago
wp_user_helper.php
3 months ago
pages_helper.php
108 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 | * Get page ID by slug with status published |
| 85 | * @param $slug |
| 86 | * @return string|null |
| 87 | */ |
| 88 | public static function get_page_by_slug( $slug ) { |
| 89 | global $wpdb; |
| 90 | 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 ) ); |
| 91 | } |
| 92 | |
| 93 | /** |
| 94 | * save default pages settings |
| 95 | * @param array $settings |
| 96 | * @param $value |
| 97 | * |
| 98 | * @return void |
| 99 | */ |
| 100 | private static function save_default_pages_settings( array $settings, $value ): void { |
| 101 | foreach ( $settings as $name ) { |
| 102 | if ( ! OsSettingsHelper::get_settings_value( $name ) ) { |
| 103 | OsSettingsHelper::save_setting_by_name( $name, $value ); |
| 104 | } |
| 105 | } |
| 106 | } |
| 107 | } |
| 108 |