balmet.com

Unnamed repository; edit this file 'description' to name the repository.
Log | Files | Refs

class-init.php (6369B)


      1 <?php // phpcs:ignore WordPress.Files.FileName
      2 
      3 /**
      4  * Initialize the Redux Template Library.
      5  *
      6  * @since 4.0.0
      7  * @package Redux Framework
      8  */
      9 
     10 namespace ReduxTemplates;
     11 
     12 use ReduxTemplates;
     13 
     14 if ( ! defined( 'ABSPATH' ) ) {
     15 	exit; // Exit if accessed directly.
     16 }
     17 
     18 /**
     19  * Redux Templates Init Class
     20  *
     21  * @since 4.0.0
     22  */
     23 class Init {
     24 
     25 	/**
     26 	 * Default left value
     27 	 *
     28 	 * @var int
     29 	 */
     30 	public static $default_left = 5;
     31 
     32 	/**
     33 	 * Init constructor.
     34 	 *
     35 	 * @access public
     36 	 */
     37 	public function __construct() {
     38 		global $pagenow;
     39 
     40 		if ( 'widgets.php' === $pagenow ) {
     41 			return;
     42 		}
     43 
     44 		add_action( 'init', array( $this, 'load' ) );
     45 
     46 		if ( did_action( 'init' ) ) { // In case the devs load it at the wrong place.
     47 			$this->load();
     48 		}
     49 
     50 		if ( false === \Redux_Core::$redux_templates_enabled ) {
     51 			return;
     52 		}
     53 
     54 		// Editor Load.
     55 		add_action( 'enqueue_block_editor_assets', array( $this, 'editor_assets' ), 1 );
     56 		// Admin Load.
     57 		add_action( 'admin_enqueue_scripts', array( $this, 'admin_assets' ) );
     58 		// Initiate the custom css fields.
     59 		Gutenberg_Custom_CSS::instance();
     60 
     61 	}
     62 
     63 	/**
     64 	 * Load everything up after init.
     65 	 *
     66 	 * @access public
     67 	 * @since 4.0.0
     68 	 */
     69 	public static function load() {
     70 		new ReduxTemplates\API();
     71 		new ReduxTemplates\Templates();
     72 		new ReduxTemplates\Notice_Overrides();
     73 	}
     74 
     75 	/**
     76 	 * Get local contents of a file.
     77 	 *
     78 	 * @param string $file_path File path.
     79 	 * @access public
     80 	 * @since 4.0.0
     81 	 * @return string
     82 	 */
     83 	public static function get_local_file_contents( $file_path ) {
     84 		$fs = \Redux_Filesystem::get_instance();
     85 		return $fs->get_contents( $file_path );
     86 	}
     87 
     88 	/**
     89 	 * Load Editor Styles and Scripts.
     90 	 *
     91 	 * @access public
     92 	 * @since 4.0.0
     93 	 */
     94 	public function editor_assets() {
     95 		$fs  = \Redux_Filesystem::get_instance();
     96 		$min = \Redux_Functions::is_min();
     97 
     98 		// Little safety here for developers.
     99 		if ( ! $fs->file_exists( REDUXTEMPLATES_DIR_PATH . "assets/js/redux-templates{$min}.js" ) ) {
    100 			if ( '.min' === $min ) {
    101 				$min = '';
    102 			} else {
    103 				$min = '.min';
    104 			}
    105 		}
    106 		$version = REDUXTEMPLATES_VERSION;
    107 		// When doing local dev work. Otherwise follow the check for dev_mode or not.
    108 		if ( defined( 'REDUX_PLUGIN_FILE' ) ) {
    109 			if ( $fs->file_exists( trailingslashit( dirname( REDUX_PLUGIN_FILE ) ) . 'local_developer.txt' ) ) {
    110 				$min = '';
    111 			}
    112 			$version = time();
    113 		}
    114 		$min = ''; // Fix since our min'd file isn't working.
    115 
    116 		wp_enqueue_script(
    117 			'redux-templates-js',
    118 			plugins_url( "assets/js/redux-templates{$min}.js", REDUXTEMPLATES_FILE ),
    119 			array( 'code-editor', 'csslint', 'wp-i18n', 'wp-blocks', 'wp-components', 'wp-compose', 'wp-data', 'wp-editor', 'wp-element', 'wp-hooks' ),
    120 			$version,
    121 			true
    122 		);
    123 
    124 		wp_set_script_translations( 'redux-templates-js', 'redux-templates' );
    125 
    126 		// Backend editor scripts: common vendor files.
    127 		wp_enqueue_script(
    128 			'redux-templates-js-vendor',
    129 			plugins_url( "assets/js/vendor{$min}.js", REDUXTEMPLATES_FILE ),
    130 			array(),
    131 			$version,
    132 			true
    133 		);
    134 
    135 		// We started using the CSS variables. This gives us the function before it's put in core.
    136 		if ( version_compare( get_bloginfo( 'version' ), '5.5', '<' ) ) {
    137 			if ( ! defined( 'GUTENBERG_VERSION' ) || ( defined( 'GUTENBERG_VERSION' ) && version_compare( GUTENBERG_VERSION, '8.5.1', '<' ) ) ) {
    138 				wp_register_style( 'redux-templates-gutenberg-compatibility', false, array(), $version );
    139 				wp_enqueue_style( 'redux-templates-gutenberg-compatibility' );
    140 				wp_add_inline_style( 'redux-templates-gutenberg-compatibility', ':root {--wp-admin-theme-color: #007cba;}' );
    141 			}
    142 		}
    143 
    144 		$global_vars = array(
    145 			'i18n'              => 'redux-framework',
    146 			'plugin'            => REDUXTEMPLATES_DIR_URL,
    147 			'mokama'            => \Redux_Helpers::mokama(),
    148 			'key'               => \base64_encode( \Redux_Functions::gs() ), // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions.obfuscation_base64_encode
    149 			'version'           => \Redux_Core::$version,
    150 			'supported_plugins' => array(), // Load the supported plugins.
    151 			'tos'               => \Redux_Connection_Banner::tos_blurb( 'import_wizard' ),
    152 		);
    153 		if ( ! $global_vars['mokama'] ) {
    154 			// phpcs:disable Squiz.PHP.CommentedOutCode
    155 			// delete_user_meta( get_current_user_id(), '_redux_templates_counts'); // To test left.
    156 			$global_vars['left'] = ReduxTemplates\Init::left( get_current_user_id() );
    157 
    158 			// phpcs:ignore
    159 			// delete_user_meta( get_current_user_id(), '_redux_welcome_guide' ); // For testing.
    160 			if ( \Redux_Helpers::is_gutenberg_page() && $global_vars['left'] === self::$default_left ) {
    161 				// We don't want to show unless Gutenberg is running, and they haven't tried the library yet.
    162 				$launched = get_user_meta( get_current_user_id(), '_redux_welcome_guide', true );
    163 				if ( '1' !== $launched ) {
    164 					$global_vars['welcome'] = 1;
    165 				}
    166 			}
    167 		}
    168 
    169 		if ( ! $global_vars['mokama'] ) {
    170 			$global_vars['u'] = rtrim( \Redux_Functions_Ex::get_site_utm_url( '', 'library', true ), '1' );
    171 		}
    172 
    173 		// TODO - Only have this show up After 2 imports and Redux installed for a week. If they dismissed, then show up again in 30 days one last time.
    174 		// phpcs:ignore Squiz.Commenting.InlineComment.InvalidEndChar
    175 		// $global_vars['nps'] = __( 'Hey there. You\'ve been using Redux for a bit now, would you mind letting us know how likely you are to recommend Redux to a friend or colleague?', 'redux-framework' );
    176 
    177 		wp_localize_script(
    178 			'redux-templates-js',
    179 			'redux_templates',
    180 			$global_vars
    181 		);
    182 
    183 		wp_enqueue_style(
    184 			'redux-fontawesome',
    185 			REDUXTEMPLATES_DIR_URL . 'assets/css/font-awesome.min.css',
    186 			false,
    187 			$version
    188 		);
    189 		$extra_css = ReduxTemplates\Templates::inline_editor_css();
    190 		if ( ! empty( $extra_css ) ) {
    191 			wp_add_inline_style( 'redux-fontawesome', $extra_css );
    192 		}
    193 	}
    194 
    195 	/**
    196 	 * Admin Style & Script.
    197 	 *
    198 	 * @access public
    199 	 * @since 4.0.0
    200 	 */
    201 	public function admin_assets() {
    202 		wp_enqueue_style(
    203 			'redux-templates-bundle',
    204 			REDUXTEMPLATES_DIR_URL . 'assets/css/admin.min.css',
    205 			false,
    206 			REDUXTEMPLATES_VERSION
    207 		);
    208 	}
    209 
    210 	/**
    211 	 * Get the items left.
    212 	 *
    213 	 * @param int $uid User ID number.
    214 	 * @access public
    215 	 * @since 4.1.18
    216 	 * @return int
    217 	 */
    218 	public static function left( $uid ) {
    219 		$count = get_user_meta( $uid, '_redux_templates_counts', true );
    220 		if ( empty( $count ) ) {
    221 			$count = self::$default_left;
    222 		}
    223 		if ( $count <= 0 ) {
    224 			$count = 0;
    225 		}
    226 
    227 		return $count;
    228 	}
    229 
    230 }
    231 
    232 new Init();