PluginProbe
Reduce Unused CSS Solution with Critical CSS For WP / trunk
Reduce Unused CSS Solution with Critical CSS For WP vtrunk
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 trunk, at critical-css-for-wp.php

155 lines 5.9 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.24
6 * Author: Magazine3
7 * Author URI: https://magazine3.company/
8 * Donate link: https://www.paypal.me/Kaludi/25
9 * Text Domain: critical-css-for-wp
10 * Domain Path: /languages
11 * License: GPL2
12 *
13 * @package critical-css-for-wp
14 */
15
16 // Exit if accessed directly.
17 if ( ! defined( 'ABSPATH' ) ) {
18 exit;
19 }
20
21 define( 'CRITICAL_CSS_FOR_WP_VERSION', '1.0.24' );
22 define( 'CRITICAL_CSS_FOR_WP_PLUGIN_URI', plugin_dir_url( __FILE__ ) );
23 define( 'CRITICAL_CSS_FOR_WP_PLUGIN_DIR', plugin_dir_path( __FILE__ ) );
24
25 /**
26 * Critical css cache path
27 */
28
29 define( 'CCWP_CACHE_NAME', 'ccwp_cleared_timestamp' );
30 define( 'CRITICAL_CSS_FOR_WP_CSS_DIR', WP_CONTENT_DIR . '/cache/critical-css-for-wp/css/' );
31 define( 'CCWP_JS_EXCLUDE_CACHE_DIR', WP_CONTENT_DIR . '/cache/critical-css-for-wp/excluded-js/' );
32 define( 'CCWP_JS_EXCLUDE_CACHE_URL', site_url( '/wp-content/cache/critical-css-for-wp/excluded-js/' ) );
33 define( 'CRITICAL_CSS_FOR_WP_CSS_DIR_ALT', WP_CONTENT_DIR . '/ccwp-cache/css/' );
34
35 require_once CRITICAL_CSS_FOR_WP_PLUGIN_DIR . 'includes/common.php';
36 require_once CRITICAL_CSS_FOR_WP_PLUGIN_DIR . 'admin/settings.php';
37 require_once CRITICAL_CSS_FOR_WP_PLUGIN_DIR . 'includes/class-critical-css-for-wp.php';
38
39
40 add_action( 'admin_enqueue_scripts', 'ccfwp_admin_enqueue' );
41
42 /**
43 * Enqueue admin scripts
44 *
45 * @param string $check The page hook.
46 */
47 function ccfwp_admin_enqueue( $check ) {
48 if ( ! is_admin() ) {
49 return;
50 }
51 if ( 'toplevel_page_critical-css-for-wp' !== $check ) {
52 return;
53 }
54 wp_enqueue_script( 'ccfwp-datatable-script', CRITICAL_CSS_FOR_WP_PLUGIN_URI . '/admin/js/jquery.dataTables.min.js', array( 'jquery' ), CRITICAL_CSS_FOR_WP_VERSION, true );
55 wp_enqueue_style( 'ccfwp-datatable-style', CRITICAL_CSS_FOR_WP_PLUGIN_URI . '/admin/css/jquery.dataTables.min.css', array(), CRITICAL_CSS_FOR_WP_VERSION );
56
57 $data = array(
58 'ccfwp_security_nonce' => wp_create_nonce( 'ccfwp_ajax_check_nonce' ),
59 );
60 $min = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
61 wp_register_script( 'ccfwp-admin-js', CRITICAL_CSS_FOR_WP_PLUGIN_URI . "/admin/js/script{$min}.js", array( 'ccfwp-datatable-script' ), CRITICAL_CSS_FOR_WP_VERSION, true );
62 wp_localize_script( 'ccfwp-admin-js', 'ccfwp_localize_data', $data );
63 wp_enqueue_script( 'ccfwp-admin-js' );
64 }
65
66 add_action( 'init', 'ccfwp_load_js_data' );
67
68 /**
69 * Load js data
70 */
71 function ccfwp_load_js_data() {
72 require_once CRITICAL_CSS_FOR_WP_PLUGIN_DIR . 'includes/javascript/delay-js.php';
73 }
74
75 register_activation_hook( __FILE__, 'ccfwp_on_activate' );
76 /**
77 * On plugin activation
78 *
79 * @param bool $network_wide Network wide activation.
80 */
81 function ccfwp_on_activate( $network_wide ) {
82 global $wpdb;
83
84 if ( is_multisite() && $network_wide ) {
85 $blog_ids = get_sites();
86 foreach ( $blog_ids as $blog_id ) {
87 switch_to_blog( $blog_id );
88 ccfwp_on_install();
89 restore_current_blog();
90 }
91 } else {
92 ccfwp_on_install();
93 }
94 }
95
96 /**
97 * On plugin install add tables
98 */
99 function ccfwp_on_install() {
100 $charset_collate = '';
101 $engine = '';
102
103 global $wpdb;
104 require_once ABSPATH . 'wp-admin/includes/upgrade.php';
105
106 if ( ! empty( $wpdb->charset ) ) {
107 $charset_collate .= " DEFAULT CHARACTER SET {$wpdb->charset}";
108 }
109 if ( $wpdb->has_cap( 'collation' ) && ! empty( $wpdb->collate ) ) {
110 $charset_collate .= " COLLATE {$wpdb->collate}";
111 }
112 //phpcs:ignore -- Reason: No need to escape query
113 $found_engine = $wpdb->get_var( $wpdb->prepare( 'SELECT ENGINE FROM `information_schema`.`TABLES` WHERE `TABLE_SCHEMA` = %s AND `TABLE_NAME` = %s;', array( DB_NAME, $wpdb->prefix . 'posts' ) ) );
114
115 if ( strtolower( $found_engine ) === 'innodb' ) {
116 $engine = ' ENGINE=InnoDB';
117 }
118 //phpcs:ignore -- Reason: No need to escape query
119 $found_tables = $wpdb->get_col( "SHOW TABLES LIKE '{$wpdb->prefix}critical_css%';" );
120
121 if ( ! in_array( "{$wpdb->prefix}critical_css_for_wp_urls", $found_tables ) ) {
122
123 dbDelta(
124 "CREATE TABLE `{$wpdb->prefix}critical_css_for_wp_urls` (
125 `id` bigint( 20 ) unsigned NOT NULL AUTO_INCREMENT,
126 `url_id` bigint( 20 ) unsigned NOT NULL,
127 `type` varchar(20),
128 `type_name` varchar(50),
129 `url` varchar(250) NOT NULL,
130 `status` varchar(20) NOT NULL default 'queue',
131 `cached_name` varchar(100),
132 `created_at` datetime NOT NULL,
133 `updated_at` timestamp NOT NULL DEFAULT current_timestamp() ON UPDATE current_timestamp(),
134 `failed_error` text NOT NULL Default '',
135 UNIQUE KEY `url` ( `url` ),
136 PRIMARY KEY (`id`)
137 ) " . $charset_collate . $engine . ';'
138 );
139 }
140 }
141 /**
142 * Add settings link
143 *
144 * @param array $links The plugin links.
145 */
146 function ccfwp_plugin_settings_links( $links ) {
147 $custom_urls = array();
148 $custom_urls[] = '<a href="' . esc_url(admin_url( 'admin.php?page=critical-css-for-wp' )) . '">' . esc_html__( 'Dashboard' ,'critical-css-for-wp') . '</a>';
149 $custom_urls[] = '<a href="' . esc_url(admin_url( 'admin.php?page=critical-css-for-wp&tab=advance' )) . '">' . esc_html__( 'Settings' ,'critical-css-for-wp') . '</a>';
150 $custom_urls[] = '<a href="' . esc_url(admin_url( 'admin.php?page=critical-css-for-wp&tab=support' )) . '">' . esc_html__( 'Support' , 'critical-css-for-wp') . '</a>';
151 return array_merge( $custom_urls, $links );
152 }
153 $ccfwp_plugin = plugin_basename( __FILE__ );
154 add_filter( "plugin_action_links_$ccfwp_plugin", 'ccfwp_plugin_settings_links' );
155