-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxwp-critical-path.php
More file actions
85 lines (70 loc) · 2.74 KB
/
xwp-critical-path.php
File metadata and controls
85 lines (70 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
<?php
/**
* Plugin Name: XWP Critical Path
* Plugin URI: https://xwp.co/
* Description: Site-specific LCP-focused performance optimizations
* Version: 1.0.1
* Author: XWP
* Author URI: https://xwp.co/
*
* @package Optimization
*/
namespace XWP\Performance;
const MAIN_DIR = __DIR__;
const VERSION = '1.0.1';
// Initialize text domain for internationalization
add_action( 'init', __NAMESPACE__ . '\load_textdomain' );
/**
* Load plugin text domain for internationalization
*/
function load_textdomain() {
load_plugin_textdomain(
'xwp-critical-path',
false,
dirname( plugin_basename( __FILE__ ) ) . '/languages/'
);
}
// Priority constants for better maintainability
const PRIORITY_EARLY = 1; // For actions that need to run very early
const PRIORITY_DEFAULT = 10; // WordPress default priority
const PRIORITY_LATE = 100; // For cleanup and late modifications
const PRIORITY_VERY_LATE = 999; // For final modifications
// ======================================================================
// Admin Settings
// ======================================================================
// Load admin settings page
require_once MAIN_DIR . '/includes/admin-settings.php';
// Add settings link on plugins page
add_filter( 'plugin_action_links_' . plugin_basename( __FILE__ ), __NAMESPACE__ . '\add_settings_link' );
/**
* Add settings link to plugins page
*
* @param array $links Existing plugin action links.
* @return array Modified plugin action links.
*/
function add_settings_link( $links ) {
$settings_link = '<a href="' . esc_url( admin_url( 'options-general.php?page=xwp_critical_path' ) ) . '">' . __( 'Settings', 'xwp-critical-path' ) . '</a>';
array_unshift( $links, $settings_link );
return $links;
}
// ======================================================================
// Disable assets.
// ======================================================================
// Disable stylesheets.
require_once MAIN_DIR . '/includes/dequeue-stylesheet.php';
// Disable scripts.
require_once MAIN_DIR . '/includes/dequeue-scripts.php';
// ======================================================================
// Set assets as non render blocking.
// ======================================================================
// Defer stylesheets.
require_once MAIN_DIR . '/includes/defer-stylesheets.php';
// Defer JS scripts.
require_once MAIN_DIR . '/includes/defer-scripts.php';
// ======================================================================
// Load assets quickly.
// ======================================================================
// Load Gutenberg block CSS library inline.
require_once MAIN_DIR . '/includes/load-gutenberg-css-inline.php';
// Preload assets (CSS, fonts).
require_once MAIN_DIR . '/includes/preload-assets.php';