is_mp_active() ) { return; } // Add MP Default options add_filter( 'appointments_default_options', array( $this, 'default_options' ) ); // Add settings section add_action( 'appointments_settings_tab-main-section-payments', array( $this, 'show_settings' ) ); add_filter( 'app-options-before_save', array( $this, 'save_settings' ) ); if ( ! $this->is_integration_active() ) { return; } if ( defined( 'MP_VERSION' ) && version_compare( MP_VERSION, '3.0', '>=' ) ) { require_once( 'marketpress/class_app_mp_bridge.php' ); App_MP_Bridge::serve(); } else { require_once( 'marketpress/class_app_mp_bridge_legacy.php' ); App_MP_Bridge_Legacy::serve(); } add_action( 'wp_ajax_make_an_appointment_mp_page', array( $this, 'create_page' ) ); } private function is_mp_active() { // class_app_mp_bridge (for MP>3.0) // class_app_mp_bridge_legacy (for MP < 3.0) global $mp; return class_exists( 'MarketPress' ) && is_object( $mp ); } private function is_integration_active() { $options = appointments_get_options(); return $this->is_mp_active() && $options['use_mp'] && $options['payment_required'] === 'yes'; } /** * Add default MP options to Appointments options * * @param array $options * * @return array */ public function default_options( $options ) { $mp_options = array( 'use_mp' => false, 'make_an_appointment_product' => false, 'app_page_type_mp' => 'one_month', ); return array_merge( $options, $mp_options ); } public function show_settings() { $options = appointments_get_options(); $product_page = get_page_by_title( 'Appointment', OBJECT, 'product' ); ?>

Note: You already have such a page. If you check this checkbox, another page with the same title will be created. ', 'appointments' ) ?> |

__( 'Something went wrong!', 'appointments' ), ); if ( ! isset( $_POST['_wpnonce'] ) || ! isset( $_POST['app_page_type'] ) || ! wp_verify_nonce( $_POST['_wpnonce'], 'appointment-create-page' ) ) { wp_send_json_error( $data ); } $tpl = ! empty( $_POST['app_page_type'] ) ? $_POST['app_page_type'] : false; $page_id = wp_insert_post( array( 'post_title' => _x( 'Appointment', 'Default page name for MarketPress integration.', 'appointments' ), 'post_status' => 'publish', 'post_type' => 'product', 'post_content' => App_Template::get_default_page_template( $tpl ), 'meta_input' => array( 'product_type' => 'digital', // Set a meta to define this is an app mp product 'mp_app_product' => 1, ), ) ); if ( $page_id ) { add_post_meta( $page_id, 'file_url', get_permalink( $page_id ) ); add_post_meta( $page_id, 'sku', 'appointment-'. $page_id ); $data = array( 'message' => sprintf( __( 'Page was created successfuly: %s', 'appointments' ), sprintf( '%s', esc_url( get_page_link( $page_id ) ), esc_html__( 'View page', 'appointments' ) ) ), ); wp_send_json_success( $data ); } wp_send_json_error( $data ); } } new Appointments_Integrations_MarketPress();