Skip to content

Commit c46fbec

Browse files
committed
Adding support to update the plugin via GitHub
1 parent 9b985af commit c46fbec

File tree

110 files changed

+11614
-30
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

110 files changed

+11614
-30
lines changed

README.md

+13-28
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,9 @@
11
# WP Light
2+
23
Create a lighter and more performant WordPress by removing things you don’t need.
34

45
## Description
6+
57
WordPress out of the box includes several things in the head section of your theme that you may never use. If you’re a clean freak like me, you may want to limit or control exactly what goes into your head section.
68

79
There are future plans to give you control over what to keep and what to remove but for now, activating this plugin will remove the following.
@@ -15,31 +17,31 @@ remove_action('wp_head', 'wp_generator');
1517
1618
// remove rss feed links (e.g. <link rel="alternate" type="application/rss+xml" title="Site Feed" href="/feed/" /> <link rel="alternate" type="application/rss+xml" title="Site Comments Feed" href="/comments/feed/" />)
1719
remove_action('wp_head', 'feed_links', 2);
18-
20+
1921
// remove all extra rss feed links
2022
remove_action('wp_head', 'feed_links_extra', 3);
21-
23+
2224
// remove link to index page
2325
remove_action('wp_head', 'index_rel_link');
24-
26+
2527
// remove wlwmanifest.xml (e.g. needed to support windows live writer) | <link rel="https://api.w.org/" href="/wp-json/" /><link rel="wlwmanifest" type="application/wlwmanifest+xml" href="/wp-includes/wlwmanifest.xml" />
2628
remove_action('wp_head', 'wlwmanifest_link');
27-
29+
2830
// remove random post link
2931
remove_action('wp_head', 'start_post_rel_link', 10, 0);
30-
32+
3133
// remove parent post link
3234
remove_action('wp_head', 'parent_post_rel_link', 10, 0);
33-
34-
// remove the next and previous post links
35+
36+
// remove the next and previous post links
3537
remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0);
3638
37-
// remove adjacent post rel link
39+
// remove adjacent post rel link
3840
remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);
39-
41+
4042
// remove JSON link from head (e.g. <link rel="https://api.w.org/" href="/wp-json/" /><link rel="alternate" type="application/json" href="/wp-json/wp/v2/posts/15" /><link rel="canonical" href="/test/" />)
4143
remove_action('wp_head', 'rest_output_link_wp_head');
42-
44+
4345
// remove shortlink (i.e. <link rel='shortlink' href='/?p=15' />)
4446
remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);
4547
@@ -51,24 +53,7 @@ remove_action( 'wp_print_styles', 'print_emoji_styles' );
5153
```
5254

5355
## Installation
56+
5457
1. Upload `wp-light.php` to the `/wp-content/plugins/` directory
5558
2. Activate the plugin through the ‘Plugins’ menu in WordPress
5659
3. Grab some coffee ☕
57-
58-
### Changelog
59-
60-
= 1.0 =
61-
* Added `remove_action('wp_head', 'rsd_link’);`
62-
* Added `remove_action('wp_head', 'wp_generator');`
63-
* Added `remove_action('wp_head', 'feed_links', 2);`
64-
* Added `remove_action('wp_head', 'feed_links_extra', 3);`
65-
* Added `remove_action('wp_head', 'index_rel_link');`
66-
* Added `remove_action('wp_head', 'wlwmanifest_link');`
67-
* Added `remove_action('wp_head', 'start_post_rel_link', 10, 0);`
68-
* Added `remove_action('wp_head', 'parent_post_rel_link', 10, 0);`
69-
* Added `remove_action('wp_head', 'adjacent_posts_rel_link', 10, 0);`
70-
* Added `remove_action('wp_head', 'adjacent_posts_rel_link_wp_head', 10, 0);`
71-
* Added `remove_action('wp_head', 'rest_output_link_wp_head');`
72-
* Added `remove_action('wp_head', 'wp_shortlink_wp_head', 10, 0);`
73-
* Added `remove_action( 'wp_head', 'print_emoji_detection_script', 7 );`
74-
* Added `remove_action( 'wp_print_styles', 'print_emoji_styles' );`

plugin-update-checker/.editorconfig

+15
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
[*]
2+
charset=utf-8
3+
end_of_line=lf
4+
insert_final_newline=false
5+
indent_style=tab
6+
tab_width=4
7+
8+
[{phpunit.xml.dist,*.jhm,*.xslt,*.xul,*.rng,*.xsl,*.xsd,*.ant,*.tld,*.fxml,*.jrxml,*.xml,*.jnlp,*.wsdl}]
9+
indent_style=space
10+
indent_size=4
11+
12+
[*.svg]
13+
indent_style=space
14+
indent_size=4
15+

plugin-update-checker/.gitignore

+40
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
# Created by .ignore support plugin (hsz.mobi)
2+
### JetBrains template
3+
# Covers JetBrains IDEs: IntelliJ, RubyMine, PhpStorm, AppCode, PyCharm, CLion, Android Studio, WebStorm and Rider
4+
# Reference: https://intellij-support.jetbrains.com/hc/en-us/articles/206544839
5+
6+
# The entire IDEA/PhpStorm directory
7+
.idea/
8+
9+
# CMake
10+
cmake-build-*/
11+
12+
# Mongo Explorer plugin
13+
.idea/**/mongoSettings.xml
14+
15+
# File-based project format
16+
*.iws
17+
18+
# IntelliJ
19+
out/
20+
21+
# mpeltonen/sbt-idea plugin
22+
.idea_modules/
23+
24+
# JIRA plugin
25+
atlassian-ide-plugin.xml
26+
27+
# Cursive Clojure plugin
28+
.idea/replstate.xml
29+
30+
# Crashlytics plugin (for Android Studio and IntelliJ)
31+
com_crashlytics_export_strings.xml
32+
crashlytics.properties
33+
crashlytics-build.properties
34+
fabric.properties
35+
36+
# Editor-based Rest Client
37+
.idea/httpRequests
38+
39+
# Android studio 3.1+ serialized cache file
40+
.idea/caches/build_file_checksums.ser
+6
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
<?php
2+
if ( !class_exists('Puc_v4_Factory', false) ):
3+
4+
class Puc_v4_Factory extends Puc_v4p10_Factory { }
5+
6+
endif;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,63 @@
1+
<?php
2+
3+
if ( !class_exists('Puc_v4p10_Autoloader', false) ):
4+
5+
class Puc_v4p10_Autoloader {
6+
private $prefix = '';
7+
private $rootDir = '';
8+
private $libraryDir = '';
9+
10+
private $staticMap;
11+
12+
public function __construct() {
13+
$this->rootDir = dirname(__FILE__) . '/';
14+
$nameParts = explode('_', __CLASS__, 3);
15+
$this->prefix = $nameParts[0] . '_' . $nameParts[1] . '_';
16+
17+
$this->libraryDir = $this->rootDir . '../..';
18+
if ( !self::isPhar() ) {
19+
$this->libraryDir = realpath($this->libraryDir);
20+
}
21+
$this->libraryDir = $this->libraryDir . '/';
22+
23+
$this->staticMap = array(
24+
'PucReadmeParser' => 'vendor/PucReadmeParser.php',
25+
'Parsedown' => 'vendor/Parsedown.php',
26+
'Puc_v4_Factory' => 'Puc/v4/Factory.php',
27+
);
28+
29+
spl_autoload_register(array($this, 'autoload'));
30+
}
31+
32+
/**
33+
* Determine if this file is running as part of a Phar archive.
34+
*
35+
* @return bool
36+
*/
37+
private static function isPhar() {
38+
//Check if the current file path starts with "phar://".
39+
static $pharProtocol = 'phar://';
40+
return (substr(__FILE__, 0, strlen($pharProtocol)) === $pharProtocol);
41+
}
42+
43+
public function autoload($className) {
44+
if ( isset($this->staticMap[$className]) && file_exists($this->libraryDir . $this->staticMap[$className]) ) {
45+
/** @noinspection PhpIncludeInspection */
46+
include ($this->libraryDir . $this->staticMap[$className]);
47+
return;
48+
}
49+
50+
if (strpos($className, $this->prefix) === 0) {
51+
$path = substr($className, strlen($this->prefix));
52+
$path = str_replace('_', '/', $path);
53+
$path = $this->rootDir . $path . '.php';
54+
55+
if (file_exists($path)) {
56+
/** @noinspection PhpIncludeInspection */
57+
include $path;
58+
}
59+
}
60+
}
61+
}
62+
63+
endif;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,186 @@
1+
<?php
2+
if ( !class_exists('Puc_v4p10_DebugBar_Extension', false) ):
3+
4+
class Puc_v4p10_DebugBar_Extension {
5+
const RESPONSE_BODY_LENGTH_LIMIT = 4000;
6+
7+
/** @var Puc_v4p10_UpdateChecker */
8+
protected $updateChecker;
9+
protected $panelClass = 'Puc_v4p10_DebugBar_Panel';
10+
11+
public function __construct($updateChecker, $panelClass = null) {
12+
$this->updateChecker = $updateChecker;
13+
if ( isset($panelClass) ) {
14+
$this->panelClass = $panelClass;
15+
}
16+
17+
add_filter('debug_bar_panels', array($this, 'addDebugBarPanel'));
18+
add_action('debug_bar_enqueue_scripts', array($this, 'enqueuePanelDependencies'));
19+
20+
add_action('wp_ajax_puc_v4_debug_check_now', array($this, 'ajaxCheckNow'));
21+
}
22+
23+
/**
24+
* Register the PUC Debug Bar panel.
25+
*
26+
* @param array $panels
27+
* @return array
28+
*/
29+
public function addDebugBarPanel($panels) {
30+
if ( $this->updateChecker->userCanInstallUpdates() ) {
31+
$panels[] = new $this->panelClass($this->updateChecker);
32+
}
33+
return $panels;
34+
}
35+
36+
/**
37+
* Enqueue our Debug Bar scripts and styles.
38+
*/
39+
public function enqueuePanelDependencies() {
40+
wp_enqueue_style(
41+
'puc-debug-bar-style-v4',
42+
$this->getLibraryUrl("/css/puc-debug-bar.css"),
43+
array('debug-bar'),
44+
'20171124'
45+
);
46+
47+
wp_enqueue_script(
48+
'puc-debug-bar-js-v4',
49+
$this->getLibraryUrl("/js/debug-bar.js"),
50+
array('jquery'),
51+
'20170516'
52+
);
53+
}
54+
55+
/**
56+
* Run an update check and output the result. Useful for making sure that
57+
* the update checking process works as expected.
58+
*/
59+
public function ajaxCheckNow() {
60+
if ( $_POST['uid'] !== $this->updateChecker->getUniqueName('uid') ) {
61+
return;
62+
}
63+
$this->preAjaxRequest();
64+
$update = $this->updateChecker->checkForUpdates();
65+
if ( $update !== null ) {
66+
echo "An update is available:";
67+
echo '<pre>', htmlentities(print_r($update, true)), '</pre>';
68+
} else {
69+
echo 'No updates found.';
70+
}
71+
72+
$errors = $this->updateChecker->getLastRequestApiErrors();
73+
if ( !empty($errors) ) {
74+
printf('<p>The update checker encountered %d API error%s.</p>', count($errors), (count($errors) > 1) ? 's' : '');
75+
76+
foreach (array_values($errors) as $num => $item) {
77+
$wpError = $item['error'];
78+
/** @var WP_Error $wpError */
79+
printf('<h4>%d) %s</h4>', $num + 1, esc_html($wpError->get_error_message()));
80+
81+
echo '<dl>';
82+
printf('<dt>Error code:</dt><dd><code>%s</code></dd>', esc_html($wpError->get_error_code()));
83+
84+
if ( isset($item['url']) ) {
85+
printf('<dt>Requested URL:</dt><dd><code>%s</code></dd>', esc_html($item['url']));
86+
}
87+
88+
if ( isset($item['httpResponse']) ) {
89+
if ( is_wp_error($item['httpResponse']) ) {
90+
$httpError = $item['httpResponse'];
91+
/** @var WP_Error $httpError */
92+
printf(
93+
'<dt>WordPress HTTP API error:</dt><dd>%s (<code>%s</code>)</dd>',
94+
esc_html($httpError->get_error_message()),
95+
esc_html($httpError->get_error_code())
96+
);
97+
} else {
98+
//Status code.
99+
printf(
100+
'<dt>HTTP status:</dt><dd><code>%d %s</code></dd>',
101+
wp_remote_retrieve_response_code($item['httpResponse']),
102+
wp_remote_retrieve_response_message($item['httpResponse'])
103+
);
104+
105+
//Headers.
106+
echo '<dt>Response headers:</dt><dd><pre>';
107+
foreach (wp_remote_retrieve_headers($item['httpResponse']) as $name => $value) {
108+
printf("%s: %s\n", esc_html($name), esc_html($value));
109+
}
110+
echo '</pre></dd>';
111+
112+
//Body.
113+
$body = wp_remote_retrieve_body($item['httpResponse']);
114+
if ( $body === '' ) {
115+
$body = '(Empty response.)';
116+
} else if ( strlen($body) > self::RESPONSE_BODY_LENGTH_LIMIT ) {
117+
$length = strlen($body);
118+
$body = substr($body, 0, self::RESPONSE_BODY_LENGTH_LIMIT)
119+
. sprintf("\n(Long string truncated. Total length: %d bytes.)", $length);
120+
}
121+
122+
printf('<dt>Response body:</dt><dd><pre>%s</pre></dd>', esc_html($body));
123+
}
124+
}
125+
echo '<dl>';
126+
}
127+
}
128+
129+
exit;
130+
}
131+
132+
/**
133+
* Check access permissions and enable error display (for debugging).
134+
*/
135+
protected function preAjaxRequest() {
136+
if ( !$this->updateChecker->userCanInstallUpdates() ) {
137+
die('Access denied');
138+
}
139+
check_ajax_referer('puc-ajax');
140+
141+
error_reporting(E_ALL);
142+
@ini_set('display_errors', 'On');
143+
}
144+
145+
/**
146+
* Remove hooks that were added by this extension.
147+
*/
148+
public function removeHooks() {
149+
remove_filter('debug_bar_panels', array($this, 'addDebugBarPanel'));
150+
remove_action('debug_bar_enqueue_scripts', array($this, 'enqueuePanelDependencies'));
151+
remove_action('wp_ajax_puc_v4_debug_check_now', array($this, 'ajaxCheckNow'));
152+
}
153+
154+
/**
155+
* @param string $filePath
156+
* @return string
157+
*/
158+
private function getLibraryUrl($filePath) {
159+
$absolutePath = realpath(dirname(__FILE__) . '/../../../' . ltrim($filePath, '/'));
160+
161+
//Where is the library located inside the WordPress directory structure?
162+
$absolutePath = Puc_v4p10_Factory::normalizePath($absolutePath);
163+
164+
$pluginDir = Puc_v4p10_Factory::normalizePath(WP_PLUGIN_DIR);
165+
$muPluginDir = Puc_v4p10_Factory::normalizePath(WPMU_PLUGIN_DIR);
166+
$themeDir = Puc_v4p10_Factory::normalizePath(get_theme_root());
167+
168+
if ( (strpos($absolutePath, $pluginDir) === 0) || (strpos($absolutePath, $muPluginDir) === 0) ) {
169+
//It's part of a plugin.
170+
return plugins_url(basename($absolutePath), $absolutePath);
171+
} else if ( strpos($absolutePath, $themeDir) === 0 ) {
172+
//It's part of a theme.
173+
$relativePath = substr($absolutePath, strlen($themeDir) + 1);
174+
$template = substr($relativePath, 0, strpos($relativePath, '/'));
175+
$baseUrl = get_theme_root_uri($template);
176+
177+
if ( !empty($baseUrl) && $relativePath ) {
178+
return $baseUrl . '/' . $relativePath;
179+
}
180+
}
181+
182+
return '';
183+
}
184+
}
185+
186+
endif;

0 commit comments

Comments
 (0)