Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

link prefetch new feature #26

Merged
merged 28 commits into from
Dec 14, 2024
Merged
Changes from 1 commit
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
c28ad8d
added link prefetch options component, LinkPrefetch class and js for …
geckod22 Oct 23, 2024
03256c3
added defer attribute to script tag
geckod22 Oct 25, 2024
4145534
phpcs on new class
geckod22 Oct 25, 2024
ba1198a
added copy text and changed toggle style
geckod22 Nov 4, 2024
3f90470
added restapi to manage the settings, adding bottom margin to fields
geckod22 Nov 4, 2024
fe39f82
removed console.log
geckod22 Nov 7, 2024
61fa41f
fixed check for mobile
geckod22 Nov 11, 2024
8374c5f
added fix for minified js
geckod22 Nov 11, 2024
49feb01
Update includes/RestApi/LinkPrefetchController.php
geckod22 Nov 18, 2024
24dff12
Update includes/RestApi/LinkPrefetchController.php
geckod22 Nov 18, 2024
ecbdb47
updated LinkPrefetchController with more fix
geckod22 Nov 18, 2024
f743bfe
adding suggested improvements to LinkPrefetchController.php
geckod22 Nov 18, 2024
b7f0abd
removed unused Permissions class and removed LinkPrefetch new and con…
geckod22 Nov 18, 2024
1427769
defaultText.js fix
geckod22 Nov 18, 2024
62999b1
Update assets/js/linkPrefetch.js
geckod22 Nov 18, 2024
b5a5284
Update components/linkPrefetch/index.js
geckod22 Nov 18, 2024
c9c5775
moved non-react scripts to scripts folder
geckod22 Nov 18, 2024
2202638
added RestApi.php
geckod22 Nov 18, 2024
5b5c22d
applied suggestion changes to component index.js
geckod22 Nov 18, 2024
5f18dca
other fixies for RestApi and LinkPrefetch Starting
geckod22 Nov 18, 2024
af2d843
moved inline styles to file and load it
geckod22 Nov 18, 2024
d29a258
some phpcs fixiews
geckod22 Nov 18, 2024
e010497
phpcs
geckod22 Nov 18, 2024
e2170d6
linkPrefetch.js lint
geckod22 Nov 18, 2024
96f9b80
Lint js files
arunshenoy99 Nov 20, 2024
a78673c
fix for mousedown event
geckod22 Nov 27, 2024
cd5d1d8
adding minified js
geckod22 Nov 27, 2024
9fc34ae
Merge branch 'release/v2.1.0' of https://github.com/newfold-labs/wp-m…
arunshenoy99 Dec 14, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
other fixies for RestApi and LinkPrefetch Starting
  • Loading branch information
geckod22 committed Nov 18, 2024
commit 5f18dca1d4b87155e919138dc431ce30ed544d84
37 changes: 7 additions & 30 deletions includes/LinkPrefetch.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<?php

namespace NewfoldLabs\WP\Module\Performance;

use NewfoldLabs\WP\ModuleLoader\Container;
@@ -15,15 +14,6 @@ class LinkPrefetch {
*/
protected $container;

/**
* Array map of API controllers.
*
* @var array
*/
protected $controllers = array(
'NewfoldLabs\\WP\\Module\\Performance\\RestApi\\LinkPrefetchController',
);

/**
* Constructor.
*
@@ -32,27 +22,12 @@ class LinkPrefetch {
public function __construct( Container $container ) {
$this->container = $container;

add_action( 'rest_api_init', array( $this, 'register_routes' ) );
add_filter( 'newfold-runtime', array( $this, 'add_to_runtime' ) );

add_action( 'wp_enqueue_scripts', array( $this, 'enqueueScripts' ) );
add_filter( 'script_loader_tag', array( $this, 'addDefer' ), 10, 2 );
}

/**
* Register API routes.
*/
public function register_routes() {
foreach ( $this->controllers as $Controller ) {
/**
* Get an instance of the WP_REST_Controller.
*
* @var $instance \WP_REST_Controller
*/
$instance = new $Controller( $this->container );
$instance->register_routes();
}
}
/**
* Add values to the runtime object.
*
@@ -62,7 +37,7 @@ public function register_routes() {
*/
public function add_to_runtime( $sdk ) {
$values = array(
'settings' => get_option( 'nfd_linkPrefetch', $this->getDefaultSettings() ),
'settings' => get_option( 'nfd_link_prefetch_settings', static::getDefaultSettings() ),
);
return array_merge( $sdk, array( 'linkPrefetch' => $values ) );
}
@@ -73,9 +48,11 @@ public function add_to_runtime( $sdk ) {
*/
public function enqueueScripts() {
$plugin_url = $this->container->plugin()->url . $this->getScriptPath();
$settings = get_option( 'nfd_linkPrefetch', $this->getDefaultSettings() );
$settings = get_option( 'nfd_link_prefetch_settings', static::getDefaultSettings() );

if ( ! $settings['activeOnDesktop'] && ! $settings['activeOnMobile'] ) { return; }
if ( ! $settings['activeOnDesktop'] && ! $settings['activeOnMobile'] ) {
return;
}

$settings['isMobile'] = wp_is_mobile();

@@ -90,15 +67,15 @@ public function enqueueScripts() {
*/
public function getScriptPath() {
$suffix = defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ? '' : '.min';
return 'vendor/newfold-labs/wp-module-performance/assets/js/linkPrefetch' . $suffix . '.js';
return 'vendor/newfold-labs/wp-module-performance/scripts/linkPrefetch' . $suffix . '.js';
}

/**
* Get link prefetch default settings.
*
* return array
*/
public function getDefaultSettings() {
public static function getDefaultSettings() {
return array(
'activeOnDesktop' => false,
'behavior' => 'mouseHover',
7 changes: 4 additions & 3 deletions includes/Performance.php
Original file line number Diff line number Diff line change
@@ -2,9 +2,7 @@

namespace NewfoldLabs\WP\Module\Performance;

use NewfoldLabs\WP\Module\Performance\CacheTypes\Browser;
use NewfoldLabs\WP\Module\Performance\CacheTypes\File;
use NewfoldLabs\WP\Module\Performance\CacheTypes\Skip404;
use NewfoldLabs\WP\Module\Performance\RestApi\RestApi;
use NewfoldLabs\WP\ModuleLoader\Container;

/**
@@ -72,6 +70,9 @@ public function __construct( Container $container ) {
$cacheManager = new CacheManager( $container );
$cachePurger = new CachePurgingService( $cacheManager->getInstances() );

new LinkPrefetch( $container );
new RestApi();

// Ensure that purgeable cache types are enabled before showing the UI.
if ( $cachePurger->canPurge() ) {
add_action( 'admin_bar_menu', array( $this, 'adminBarMenu' ), 100 );
72 changes: 36 additions & 36 deletions includes/RestApi/RestApi.php
Original file line number Diff line number Diff line change
@@ -1,36 +1,36 @@
<?php
namespace NewfoldLabs\WP\Module\Performance\RestApi;
final class RestApi {
/**
* List of custom REST API controllers
*
* @var array
*/
protected $controllers = array(
'NewfoldLabs\\WP\\Module\\Performance\\RestApi\\LinkPrefetchController',
);
/**
* Setup the custom REST API
*/
public function __construct() {
add_action( 'rest_api_init', array( $this, 'register_routes' ) );
}
/**
* Register API routes.
*/
public function register_routes() {
foreach ( $this->controllers as $Controller ) {
/**
* Get an instance of the WP_REST_Controller.
*
* @var $instance \WP_REST_Controller
*/
$instance = new $Controller();
$instance->register_routes();
}
}
}
<?php
namespace NewfoldLabs\WP\Module\Performance\RestApi;

final class RestApi {

/**
* List of custom REST API controllers
*
* @var array
*/
protected $controllers = array(
'NewfoldLabs\\WP\\Module\\Performance\\RestApi\\LinkPrefetchController',
);

/**
* Setup the custom REST API
*/
public function __construct() {
add_action( 'rest_api_init', array( $this, 'register_routes' ) );
}

/**
* Register API routes.
*/
public function register_routes() {
foreach ( $this->controllers as $Controller ) {
/**
* Get an instance of the WP_REST_Controller.
*
* @var $instance \WP_REST_Controller
*/
$instance = new $Controller();
$instance->register_routes();
}
}
}