PluginProbe
Reduce Unused CSS Solution with Critical CSS For WP / 1.0.8
Reduce Unused CSS Solution with Critical CSS For WP v1.0.8
1.0.24 trunk 1.0.0 1.0.1 1.0.10 1.0.11 1.0.12 1.0.13 1.0.14 1.0.15 1.0.16 1.0.17 1.0.18 1.0.19 1.0.2 1.0.20 1.0.21 1.0.22 1.0.23 1.0.3 1.0.4 1.0.5 1.0.6 1.0.7 1.0.8 All 26 releases
critical-css-for-wp / critical-css-for-wp.php

critical-css-for-wp.php in Reduce Unused CSS Solution with Critical CSS For WP 1.0.8, at critical-css-for-wp.php

117 lines 4.6 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /*
3 Plugin Name: Reduce Unused CSS Solution with Critical CSS For WP
4 Description: Critical CSS For WP intends to provide great experience to the web page visitors by improving the performance of the web page. Here we'd remove the unused CSS which helps to paint fast and render the above fold content, before downloading the complete css files.
5 Version: 1.0.8
6 Author: Magazine3
7 Author URI: https://magazine3.company/
8 Donate link: https://www.paypal.me/Kaludi/25
9 Text Domain: criticalcssforwp
10 Domain Path: /languages
11 License: GPL2
12 */
13 // Exit if accessed directly.
14 if ( ! defined( 'ABSPATH' ) ) exit;
15
16 define('CRITICAL_CSS_FOR_WP_VERSION','1.0.8');
17 define('CRITICAL_CSS_FOR_WP_PLUGIN_URI', plugin_dir_url(__FILE__));
18 define('CRITICAL_CSS_FOR_WP_PLUGIN_DIR', plugin_dir_path(__FILE__));
19
20 /**
21 * Critical css cache path
22 **/
23 define('CRITICAL_CSS_FOR_WP_CSS_DIR', WP_CONTENT_DIR . "/cache/critical-css-for-wp/css/");
24
25 define('CCWP_CACHE_NAME', 'ccwp_cleared_timestamp');
26
27 define('CCWP_JS_EXCLUDE_CACHE_DIR', WP_CONTENT_DIR . "/cache/critical-css-for-wp/excluded-js/");
28 define('CCWP_JS_EXCLUDE_CACHE_URL', site_url("/wp-content/cache/critical-css-for-wp/excluded-js/"));
29
30 require_once CRITICAL_CSS_FOR_WP_PLUGIN_DIR . "includes/common.php";
31 require_once CRITICAL_CSS_FOR_WP_PLUGIN_DIR . "admin/settings.php";
32 require_once CRITICAL_CSS_FOR_WP_PLUGIN_DIR . "includes/class-critical-css.php";
33
34
35 add_action('admin_enqueue_scripts','ccfwp_admin_enqueue');
36 function ccfwp_admin_enqueue($check) {
37 if ( !is_admin() ) {
38 return;
39 }
40 if($check != 'toplevel_page_critical-css-for-wp'){
41 return;
42 }
43 wp_enqueue_script('ccfwp-datatable-script', CRITICAL_CSS_FOR_WP_PLUGIN_URI . '/admin/js/jquery.dataTables.min.js', ['jquery']);
44 wp_enqueue_style( 'ccfwp-datatable-style', CRITICAL_CSS_FOR_WP_PLUGIN_URI . '/admin/js/jquery.dataTables.min.css' );
45
46 $data = array(
47 'ccfwp_security_nonce' => wp_create_nonce('ccfwp_ajax_check_nonce')
48 );
49 wp_register_script( 'ccfwp-admin-js', CRITICAL_CSS_FOR_WP_PLUGIN_URI . '/admin/js/script.js', array('ccfwp-datatable-script'), CRITICAL_CSS_FOR_WP_VERSION , true );
50 wp_localize_script( 'ccfwp-admin-js', 'ccfwp_localize_data', $data );
51 wp_enqueue_script( 'ccfwp-admin-js' );
52 }
53
54 add_action( 'init', 'load_js_data' );
55 function load_js_data(){
56 require_once CRITICAL_CSS_FOR_WP_PLUGIN_DIR."includes/javascript/delay-js.php";
57 }
58
59 register_activation_hook( __FILE__, 'ccfwp_on_activate' );
60
61 function ccfwp_on_activate( $network_wide ) {
62 global $wpdb;
63
64 if ( is_multisite() && $network_wide ) {
65 $blog_ids = $wpdb->get_col( "SELECT blog_id FROM $wpdb->blogs" );
66 foreach ( $blog_ids as $blog_id ) {
67 switch_to_blog( $blog_id );
68 ccfwp_on_install();
69 restore_current_blog();
70 }
71 } else {
72 ccfwp_on_install();
73 }
74 }
75
76 function ccfwp_on_install(){
77
78 global $wpdb;
79
80 require_once(ABSPATH . 'wp-admin/includes/upgrade.php');
81
82 $charset_collate = $engine = '';
83
84 if(!empty($wpdb->charset)) {
85 $charset_collate .= " DEFAULT CHARACTER SET {$wpdb->charset}";
86 }
87 if($wpdb->has_cap('collation') AND !empty($wpdb->collate)) {
88 $charset_collate .= " COLLATE {$wpdb->collate}";
89 }
90
91 $found_engine = $wpdb->get_var("SELECT ENGINE FROM `information_schema`.`TABLES` WHERE `TABLE_SCHEMA` = '".DB_NAME."' AND `TABLE_NAME` = '{$wpdb->prefix}posts';");
92
93 if(strtolower($found_engine) == 'innodb') {
94 $engine = ' ENGINE=InnoDB';
95 }
96
97 $found_tables = $wpdb->get_col("SHOW TABLES LIKE '{$wpdb->prefix}critical_css%';");
98
99 if(!in_array("{$wpdb->prefix}critical_css_for_wp_urls", $found_tables)) {
100
101 dbDelta("CREATE TABLE `{$wpdb->prefix}critical_css_for_wp_urls` (
102 `id` bigint( 20 ) unsigned NOT NULL AUTO_INCREMENT,
103 `url_id` bigint( 20 ) unsigned NOT NULL,
104 `type` varchar(20),
105 `type_name` varchar(50),
106 `url` varchar(300) NOT NULL,
107 `status` varchar(20) NOT NULL default 'queue',
108 `cached_name` varchar(100),
109 `created_at` datetime NOT NULL,
110 `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
111 `failed_error` text NOT NULL Default '',
112 UNIQUE KEY `url` ( `url` ),
113 PRIMARY KEY (`id`)
114 ) ".$charset_collate.$engine.";");
115 }
116
117 }