Settings', 'Docs', ); if ( ! _is_cartflows_pro() ) { array_push( $mylinks, ' Go Pro ' ); } return array_merge( $links, $mylinks ); } /** * Initialize after Cartflows pro get loaded. */ static public function settings_admin_scripts() { // Enqueue admin scripts. if ( isset( $_REQUEST['page'] ) && CARTFLOWS_SETTINGS == $_REQUEST['page'] ) { add_action( 'admin_enqueue_scripts', __CLASS__ . '::styles_scripts' ); self::save_settings(); } } /** * Initialises the Plugin Name. * * @since 1.0.0 * @return void */ static public function initialise_plugin() { $name = 'Cartflows'; $short_name = 'Cflows'; define( 'CARTFLOWS_PLUGIN_NAME', $name ); define( 'CARTFLOWS_PLUGIN_SHORT_NAME', $short_name ); } /** * Renders the admin settings menu. * * @since 1.0.0 * @return void */ static public function menu() { if ( ! current_user_can( 'manage_options' ) ) { return; } add_menu_page( 'CartFlows', 'CartFlows', 'manage_options', CARTFLOWS_SLUG, __CLASS__ . '::render', 'data:image/svg+xml;base64,' . base64_encode( file_get_contents( CARTFLOWS_DIR . 'assets/images/cartflows-icon.svg' ) ), 39.7 ); } /** * Add submenu to admin menu. * * @since 1.0.0 */ static function submenu() { $parent_slug = CARTFLOWS_SLUG; $page_title = __( 'Settings', 'cartflows' ); $menu_title = __( 'Settings', 'cartflows' ); $capability = 'manage_options'; $menu_slug = 'cartflows_settings'; $callback = __CLASS__ . '::render'; add_submenu_page( $parent_slug, $page_title, $menu_title, $capability, $menu_slug, $callback ); } /** * Renders the admin settings. * * @since 1.0.0 * @return void */ static public function render() { $action = ( isset( $_GET['action'] ) ) ? sanitize_text_field( $_GET['action'] ) : ''; $action = ( ! empty( $action ) && '' != $action ) ? $action : 'general'; $action = str_replace( '_', '-', $action ); // Enable header icon filter below. $header_wrapper_class = apply_filters( 'cartflows_header_wrapper_class', array( $action ) ); include_once CARTFLOWS_DIR . 'includes/admin/cartflows-admin.php'; } /** * Renders the admin settings content. * * @since 1.0.0 * @return void */ static public function render_content() { $action = ( isset( $_GET['action'] ) ) ? sanitize_text_field( $_GET['action'] ) : ''; $action = ( ! empty( $action ) && '' != $action ) ? $action : 'general'; $action = str_replace( '_', '-', $action ); $action = 'general'; $header_wrapper_class = apply_filters( 'cartflows_header_wrapper_class', array( $action ) ); include_once CARTFLOWS_DIR . 'includes/admin/cartflows-general.php'; } /** * Save Global Setting options. * * @since 1.0.0 */ static public function save_common_settings() { if ( isset( $_POST['cartflows-common-settings-nonce'] ) && wp_verify_nonce( $_POST['cartflows-common-settings-nonce'], 'cartflows-common-settings' ) ) { $url = $_SERVER['REQUEST_URI']; $input_settings = array(); $new_settings = array(); if ( isset( $_POST['_cartflows_common'] ) ) { $input_settings = $_POST['_cartflows_common']; // Loop through the input and sanitize each of the values. foreach ( $input_settings as $key => $val ) { if ( is_array( $val ) ) { foreach ( $val as $k => $v ) { $new_settings[ $key ][ $k ] = ( isset( $val[ $k ] ) ) ? sanitize_text_field( $v ) : ''; } } else { $new_settings[ $key ] = ( isset( $input_settings[ $key ] ) ) ? sanitize_text_field( $val ) : ''; } } } Cartflows_Helper::update_admin_settings_option( '_cartflows_common', $new_settings, true ); $query = array( 'message' => 'saved', ); $redirect_to = add_query_arg( $query, $url ); wp_redirect( $redirect_to ); exit; } // End if statement. } /** * Save Debug Setting options. * * @since 1.1.14 */ static public function save_debug_settings() { if ( isset( $_POST['cartflows-debug-settings-nonce'] ) && wp_verify_nonce( $_POST['cartflows-debug-settings-nonce'], 'cartflows-debug-settings' ) ) { $url = $_SERVER['REQUEST_URI']; $input_settings = array(); $new_settings = array(); if ( isset( $_POST['_cartflows_debug_data'] ) ) { $input_settings = $_POST['_cartflows_debug_data']; // Loop through the input and sanitize each of the values. foreach ( $input_settings as $key => $val ) { if ( is_array( $val ) ) { foreach ( $val as $k => $v ) { $new_settings[ $key ][ $k ] = ( isset( $val[ $k ] ) ) ? sanitize_text_field( $v ) : ''; } } else { $new_settings[ $key ] = ( isset( $input_settings[ $key ] ) ) ? sanitize_text_field( $val ) : ''; } } } Cartflows_Helper::update_admin_settings_option( '_cartflows_debug_data', $new_settings, true ); $query = array( 'message' => 'saved', ); $redirect_to = add_query_arg( $query, $url ); wp_redirect( $redirect_to ); exit; } } /** * Check is cartflows admin. * * @since 1.0.0 * @return boolean */ static public function is_global_admin() { $current_screen = get_current_screen(); if ( is_object( $current_screen ) && isset( $current_screen->post_type ) && ( CARTFLOWS_FLOW_POST_TYPE === $current_screen->post_type || CARTFLOWS_STEP_POST_TYPE === $current_screen->post_type ) ) { return true; } return false; } /** * Check is flow admin. * * @since 1.0.0 * @return boolean */ static public function is_flow_edit_admin() { $current_screen = get_current_screen(); if ( is_object( $current_screen ) && isset( $current_screen->post_type ) && ( CARTFLOWS_FLOW_POST_TYPE === $current_screen->post_type ) && isset( $current_screen->base ) && ( 'post' === $current_screen->base ) ) { return true; } return false; } /** * Global Admin Scripts. * * @since 1.0.0 */ static public function global_admin_scripts() { $localize = array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'ajax_nonce' => wp_create_nonce( 'cartflows-nonce' ), ); wp_localize_script( 'jquery', 'cartflows_admin', apply_filters( 'cartflows_admin_js_localize', $localize ) ); if ( self::is_global_admin() ) { // Styles. wp_enqueue_style( 'cartflows-global-admin', CARTFLOWS_URL . 'admin/assets/css/global-admin.css', array(), CARTFLOWS_VER ); wp_style_add_data( 'cartflows-global-admin', 'rtl', 'replace' ); wp_enqueue_script( 'wcf-global-admin', CARTFLOWS_URL . 'admin/assets/js/global-admin.js', array( 'jquery' ), CARTFLOWS_VER, true ); do_action( 'cartflows_global_admin_scripts' ); } } /** * Global Admin Data. * * @since 1.0.0 */ static public function global_admin_data() { $current_screen = get_current_screen(); if ( ! $current_screen ) { return; } if ( 'edit-' . CARTFLOWS_FLOW_POST_TYPE != $current_screen->id ) { return; } $default_page_builder = Cartflows_Helper::get_common_setting( 'default_page_builder' ); ?>
wp_create_nonce( 'cartflows-widget-nonce' ), ); wp_localize_script( 'cartflows-admin-settings', 'cartflows', apply_filters( 'cartflows_js_localize', $localize ) ); do_action( 'cartflows_admin_settings_after_enqueue_scripts' ); } /** * Save All admin settings here */ static public function save_settings() { // Only admins can save settings. if ( ! current_user_can( 'manage_options' ) ) { return; } self::save_common_settings(); self::save_debug_settings(); // Let extensions hook into saving. do_action( 'cartflows_admin_settings_save' ); } /** * Get and return page URL * * @param string $menu_slug Menu name. * @since 1.0.0 * @return string page url */ static public function get_page_url( $menu_slug ) { $parent_page = self::$default_menu_position; if ( strpos( $parent_page, '?' ) !== false ) { $query_var = '&page=' . self::$plugin_slug; } else { $query_var = '?page=' . self::$plugin_slug; } $parent_page_url = admin_url( $parent_page . $query_var ); $url = $parent_page_url . '&action=' . $menu_slug; return esc_url( $url ); } /** * Admin body classes. * * Body classes to be added to tag in admin page * * @param String $classes body classes returned from the filter. * @return String body classes to be added to tag in admin page */ static public function add_admin_body_class( $classes ) { $classes .= ' cartflows-' . CARTFLOWS_VER; return $classes; } } Cartflows_Admin::init();