Learn more  » Push, build, and install  RubyGems npm packages Python packages Maven artifacts PHP packages Go Modules Bower components Debian packages RPM packages NuGet packages

jsarnowski / jsarnowski/cartflows   php

Repository URL to install this package:

Version: 1.6.11 

/ class-cartflows-admin-classes.php

<?php
/**
 * CartFlows Admin.
 *
 * @package CartFlows
 */

// Exit if accessed directly.
if ( ! defined( 'ABSPATH' ) ) {
	exit;
}

/**
 * Class Cartflows_Admin_Classes.
 */
class Cartflows_Admin_Classes {

	/**
	 * Calls on initialization
	 *
	 * @since 1.0.0
	 */
	public static function init() {

		self::init_hooks();
	}

	/**
	 * Init Hooks.
	 *
	 * @since 1.0.0
	 * @return void
	 */
	public static function init_hooks() {

		if ( ! is_admin() ) {
			return;
		}

		include_once CARTFLOWS_LEGACY_ADMIN_DIR . 'class-cartflows-admin-fields.php';

		/*
		Add CARTFLOWS menu option to admin.
		add_action( 'network_admin_menu', __CLASS__ . '::menu' );
		*/
		add_action( 'admin_menu', __CLASS__ . '::menu' );
		add_action( 'admin_menu', __CLASS__ . '::submenu', 999 );
		add_action( 'admin_menu', __CLASS__ . '::register_as_submenu', 100 );

		add_action( 'cartflows_render_admin_content', __CLASS__ . '::render_content' );

		add_action( 'admin_init', __CLASS__ . '::settings_admin_scripts' );

		/* Global Addmin Script */
		add_action( 'admin_enqueue_scripts', __CLASS__ . '::global_admin_scripts', 20 );

		add_action( 'admin_footer', __CLASS__ . '::global_admin_data', 9555 );

		add_action( 'admin_init', __CLASS__ . '::cartflows_after_save_permalinks' );

		add_filter( 'get_user_option_meta-box-order_' . CARTFLOWS_STEP_POST_TYPE, __CLASS__ . '::metabox_order' );
	}



	/**
	 * Metabox fixed orders.
	 *
	 * @param  array $metabox_orders Orders.
	 * @return array
	 */
	public static function metabox_order( $metabox_orders ) {

		if ( isset( $metabox_orders['side'] ) ) {

			$metabox_orders['side'] = str_replace(
				array(
					'wcf-checkout-settings',
					'wcf-ladning-settings',
					'wcf-optin-settings',
					'wcf-thankyou-settings',
				),
				'',
				$metabox_orders['side']
			);
		}

		return $metabox_orders;
	}

	/**
	 *  After save of permalinks.
	 */
	public static function cartflows_after_save_permalinks() {

		$has_saved_permalinks = get_option( 'cartflows_permalink_saved' );
		if ( $has_saved_permalinks ) {
			flush_rewrite_rules();
			delete_option( 'cartflows_permalink_saved' );
		}
	}


	/**
	 *  Initialize after Cartflows pro get loaded.
	 */
	public static function settings_admin_scripts() {
		// Enqueue admin scripts.
		if ( isset( $_GET['page'] ) && ( 'cartflows' === $_GET['page'] || false !== strpos( $_GET['page'], 'cartflows_' ) ) ) { //phpcs:ignore
			add_action( 'admin_enqueue_scripts', __CLASS__ . '::styles_scripts' );

			self::save_settings();
		}
	}

	/**
	 * Renders the admin settings menu.
	 *
	 * @since 1.0.0
	 * @return void
	 */
	public static 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' ) ),//phpcs:ignore
			39.7
		);

	}

	/**
	 * Add submenu to admin menu.
	 *
	 * @since 1.0.0
	 */
	public static function submenu() {

		global $submenu;

		$parent_slug = CARTFLOWS_SLUG;
		$capability  = 'manage_options';

		// Home menu.
		$submenu[ $parent_slug ][0][0] = __( 'Home', 'cartflows' ); //phpcs:ignore

		// Add settings menu.
		add_submenu_page(
			$parent_slug,
			__( 'Settings', 'cartflows' ),
			__( 'Settings', 'cartflows' ),
			$capability,
			'cartflows_settings',
			__CLASS__ . '::render'
		);
	}

	/**
	 * Add flows submenu
	 *
	 * @since 1.0.0
	 */
	public static function register_as_submenu() {
		add_submenu_page(
			CARTFLOWS_SLUG,
			__( 'Flows', 'cartflows' ),
			__( 'Flows', 'cartflows' ),
			'edit_pages',
			'edit.php?post_type=' . CARTFLOWS_FLOW_POST_TYPE
		);
	}

	/**
	 * Renders the admin settings.
	 *
	 * @since 1.0.0
	 * @return void
	 */
	public static function render() {
		$menu_page_slug = ( isset( $_GET['page'] ) ) ? sanitize_text_field( wp_unslash( $_GET['page'] ) ) : CARTFLOWS_SETTINGS; //phpcs:ignore
		$action 		= ( isset( $_GET['action'] ) ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : ''; //phpcs:ignore
		$action         = ( ! empty( $action ) && '' != $action ) ? $action : 'general';
		$action         = str_replace( '_', '-', $action );

		// Enable header icon filter below.
		$header_wrapper_class = apply_filters( 'cartflows_admin_header_wrapper_class', array( $action, $menu_page_slug ) );

		include_once CARTFLOWS_DIR . 'admin-legacy/includes/admin/cartflows-admin.php';
	}

	/**
	 * Renders the admin settings content.
	 *
	 * @since 1.0.0
	 * @param sting $menu_page_slug current page name.
	 *
	 * @return void
	 */
	public static function render_content( $menu_page_slug ) {

		if ( CARTFLOWS_SETTINGS === $menu_page_slug ) {

			$action = ( isset( $_GET['action'] ) ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : ''; //phpcs:ignore
			$action = ( ! empty( $action ) && '' != $action ) ? $action : 'general';
			$action = str_replace( '_', '-', $action );
			$action = 'general';

			include_once CARTFLOWS_DIR . 'admin-legacy/includes/admin/cartflows-general.php';
		}

		if ( 'cartflows' === $menu_page_slug ) {

			$action = ( isset( $_GET['action'] ) ) ? sanitize_text_field( wp_unslash( $_GET['action'] ) ) : ''; //phpcs:ignore
			$action = ( ! empty( $action ) && '' != $action ) ? $action : 'general';
			$action = str_replace( '_', '-', $action );
			$action = 'general';

			include_once CARTFLOWS_DIR . 'admin-legacy/includes/admin/cartflows-home.php';
		}
	}

	/**
	 * Save Global Setting options.
	 *
	 * @since 1.0.0
	 */
	public static function save_migrate_ui_settings() {

		if ( isset( $_POST['cartflows-use-new-ui-nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['cartflows-use-new-ui-nonce'] ) ), 'cartflows-use-new-ui' ) ) {

			$url = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';

			delete_option( 'cartflows-legacy-admin' );
			update_option( 'cartflows-switch-ui-notice', 'update' );

			$query = array(
				'message' => 'saved',
			);

			$redirect_to = add_query_arg( $query, $url );

			wp_safe_redirect( $redirect_to );
			exit;
		} // End if statement.
	}

	/**
	 * Save Global Setting options.
	 *
	 * @since 1.0.0
	 */
	public static function save_common_settings() {

		if ( isset( $_POST['cartflows-common-settings-nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['cartflows-common-settings-nonce'] ) ), 'cartflows-common-settings' ) ) {

			$url          = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
			$new_settings = array();

			if ( isset( $_POST['_cartflows_common'] ) ) {
				// Loop through the input and sanitize each of the values.
				$new_settings = self::sanitize_form_inputs( wp_unslash( $_POST['_cartflows_common'] ) ); //phpcs:ignore
			}

			Cartflows_Helper::update_admin_settings_option( '_cartflows_common', $new_settings, false );

			$query = array(
				'message' => 'saved',
			);

			$redirect_to = add_query_arg( $query, $url );

			wp_safe_redirect( $redirect_to );
			exit;
		} // End if statement.
	}

	/**
	 * Save Debug Setting options.
	 *
	 * @since 1.1.14
	 */
	public static function save_debug_settings() {

		if ( isset( $_POST['cartflows-debug-settings-nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['cartflows-debug-settings-nonce'] ) ), 'cartflows-debug-settings' ) ) {

			$url          = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
			$new_settings = array();

			if ( isset( $_POST['_cartflows_debug_data'] ) ) {
				$new_settings = self::sanitize_form_inputs( wp_unslash( $_POST['_cartflows_debug_data'] ) ); //phpcs:ignore
			}

			Cartflows_Helper::update_admin_settings_option( '_cartflows_debug_data', $new_settings, false );

			$query = array(
				'message' => 'saved',
			);

			$redirect_to = add_query_arg( $query, $url );

			wp_safe_redirect( $redirect_to );
			exit;

		}
	}


	/**
	 * Save permalink Setting options.
	 *
	 * @since 1.1.14
	 */
	public static function save_permalink_settings() {

		if ( isset( $_POST['cartflows-permalink-settings-nonce'] ) && wp_verify_nonce( sanitize_text_field( wp_unslash( $_POST['cartflows-permalink-settings-nonce'] ) ), 'cartflows-permalink-settings' ) ) {

			$url          = isset( $_SERVER['REQUEST_URI'] ) ? esc_url_raw( wp_unslash( $_SERVER['REQUEST_URI'] ) ) : '';
			$new_settings = array();

			if ( isset( $_POST['reset'] ) ) {
				$_POST['_cartflows_permalink'] = array(
					'permalink'           => CARTFLOWS_STEP_POST_TYPE,
					'permalink_flow_base' => CARTFLOWS_FLOW_POST_TYPE,
					'permalink_structure' => '',
				);

			}

			if ( isset( $_POST['_cartflows_permalink'] ) ) {
				$cartflows_permalink_settings = self::sanitize_form_inputs( wp_unslash( $_POST['_cartflows_permalink'] ) ); //phpcs:ignore

				if ( empty( $cartflows_permalink_settings['permalink'] ) ) {
					$new_settings['permalink'] = CARTFLOWS_STEP_POST_TYPE;
				} else {
					$new_settings['permalink'] = $cartflows_permalink_settings['permalink'];
				}
Loading ...