Skip to content

Commit

Permalink
Merge pull request #1 from code-soup/dev
Browse files Browse the repository at this point in the history
0.0.2
  • Loading branch information
Bobz-zg authored Aug 15, 2024
2 parents 4347e6c + d07584d commit 757eeba
Show file tree
Hide file tree
Showing 17 changed files with 244 additions and 45 deletions.
9 changes: 5 additions & 4 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,14 @@ Boost the performance and efficiency of your WordPress website with the Instapag

**Efficient Cache Management**

- **Automatic Cache Handling:** Automatically cache all published Instapage pages
- **Easy Cache Clearing:** With just a click, clear the entire cache or specific pages to ensure your content is always up-to-date.
- Automatically cache all published Instapage pages
- With just a click, clear the entire cache or specific pages to ensure your content is always up-to-date.
- Disable caching on per page basis

**Improved Performance**

- **Faster Page Loads:** By serving cached content, the plugin dramatically reduces the time it takes for your pages to load, enhancing user experience.
- **Reduced Server Load:** Offload server processing by delivering cached pages, making your site more resilient under heavy traffic.
- By serving cached content, the plugin dramatically reduces the time it takes for your pages to load, enhancing user experience.
- Offload server processing by delivering cached pages, making your site more resilient under heavy traffic.

**Custom User Role and Capability**

Expand Down
11 changes: 6 additions & 5 deletions README.txt
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@ Requires at least: 4.0
Requires PHP: 8.2
Stable Tag: trunk
Tags: instapage, caching, optimization
Tested up to: 4.8
Tested up to: 6.5

Boost performance and reduce server load with Instapage Cache. This add-on for Instapage lets you easily manage and clear cache to speed up page load time.

Expand All @@ -17,12 +17,13 @@ Boost the performance and efficiency of your Instapage sites with the Instapage
### Key Features

#### Efficient Cache Management
- **Automatic Cache Handling:** Automatically cache all published Instapage pages
- **Easy Cache Clearing:** With just a click, clear the entire cache or specific pages to ensure your content is always up-to-date.
- Automatically cache all published Instapage pages
- With just a click, clear the entire cache or specific pages to ensure your content is always up-to-date.
- Disable caching on per page basis

#### Improved Performance
- **Faster Page Loads:** By serving cached content, the plugin dramatically reduces the time it takes for your pages to load, enhancing user experience.
- **Reduced Server Load:** Offload server processing by delivering cached pages, making your site more resilient under heavy traffic.
- By serving cached content, the plugin dramatically reduces the time it takes for your pages to load, enhancing user experience.
- Offload server processing by delivering cached pages, making your site more resilient under heavy traffic.

#### Custom User Role and Capability
This add-on introduces a significant change to Instapage management access. Previously, only users with the Administrator role could access and manage Instapage. Now, a new custom user role, **Instapage Manager**, grants non-admin users the capability to access and manage Instapage, providing more flexibility and control..
Expand Down
10 changes: 5 additions & 5 deletions dist/assets.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"admin.css": "styles/admin-272ccf9aadcc0f7a57f4.css",
"admin.js": "scripts/admin-272ccf9aadcc0f7a57f4.js",
"scripts/388-272ccf9aadcc0f7a57f4.js": "scripts/388-272ccf9aadcc0f7a57f4.js",
"scripts/admin-272ccf9aadcc0f7a57f4.js.LICENSE.txt": "scripts/admin-272ccf9aadcc0f7a57f4.js.LICENSE.txt",
"vendor/index.js": "scripts/vendor/index-272ccf9aadcc0f7a57f4.js"
"admin.css": "styles/admin-e3ecfaa6d5ef3fb74c0e.css",
"admin.js": "scripts/admin-e3ecfaa6d5ef3fb74c0e.js",
"scripts/388-e3ecfaa6d5ef3fb74c0e.js": "scripts/388-e3ecfaa6d5ef3fb74c0e.js",
"scripts/admin-e3ecfaa6d5ef3fb74c0e.js.LICENSE.txt": "scripts/admin-e3ecfaa6d5ef3fb74c0e.js.LICENSE.txt",
"vendor/index.js": "scripts/vendor/index-e3ecfaa6d5ef3fb74c0e.js"
}

Large diffs are not rendered by default.

Large diffs are not rendered by default.

File renamed without changes.
75 changes: 67 additions & 8 deletions includes/admin/class-api-controller.php
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ public function register_routes()
array(
'methods' => \WP_REST_Server::READABLE,
'callback' => array($this, 'get_items'),
'permission_callback' => array($this, 'get_items_permissions_check'),
'permission_callback' => '__return_true',
// 'permission_callback' => array($this, 'get_items_permissions_check'),
),
)
);
Expand All @@ -41,6 +42,19 @@ public function register_routes()
),
)
);

register_rest_route(
'instapage-cache/v1',
'/toggle',
array(
array(
'methods' => \WP_REST_Server::CREATABLE,
'callback' => array($this, 'toggle_item'),
'permission_callback' => '__return_true',
// 'permission_callback' => array($this, 'get_items_permissions_check'),
),
)
);
}


Expand All @@ -50,9 +64,10 @@ public function get_items( \WP_REST_Request $request )
{
// Query args
$search = $request->get_param('search');
$paged = $request->get_param('page');
$per_page = $request->get_param('per_page');
$paged = $request->get_param('page') ? $request->get_param('page') : 1;
$per_page = $request->get_param('per_page') ? $request->get_param('per_page') : 15;
$offset = intval( ($paged - 1) * $per_page );
$disabled = $this->get_disabled_pages();

global $wpdb;

Expand All @@ -73,20 +88,20 @@ public function get_items( \WP_REST_Request $request )
/**
* Return
*/
$fs = new \WP_Filesystem_Direct('');
$items = array();

foreach( $qry as $row )
{

$fs = new \WP_Filesystem_Direct('');
$file = sprintf(
'%s/%s/index.html',
$this->get_constant('CACHE_BASE_DIR'),
trim($row['slug'], '/')
);

$new = $row;
$new['cached'] = intval( $fs->exists( $file ) );
$new = $row;
$new['cached'] = intval( $fs->exists( $file ) );
$new['cache_disabled'] = ( array_search($row['id'], $disabled) !== false );

$items[] = $new;
}
Expand All @@ -102,7 +117,11 @@ public function get_items( \WP_REST_Request $request )
}



/**
* Delete cache for single page
* This simply deletes folder of the page
* On each new request cache is served in case folder exists
*/
public function delete_item( \WP_REST_Request $request )
{
// Query args
Expand All @@ -128,6 +147,39 @@ public function delete_item( \WP_REST_Request $request )
}


/**
* Toggle Caching on/off
*/
public function toggle_item( \WP_REST_Request $request )
{
$id = $request->get_param('id');
$slug = $request->get_param('slug');

switch ( $request->get_param('action') ) {
case 'disable':
$this->disable_caching( intval($id) );

/**
* Delete existing cache
*/
if ( ! empty($slug) )
{
$fs = new \WP_Filesystem_Direct('');
$del = $fs->rmdir( $this->get_cache_dir_path( $slug ), true );
}
break;

case 'enable':
$this->enable_caching( intval($id) );
break;
}

return rest_ensure_response([
'action' => $request->get_param('action'),
]);
}


/**
* Validate user permissions when trying to deploy from docker
*/
Expand All @@ -151,6 +203,13 @@ public function get_items_permissions_check( \WP_REST_Request $request )
*/
public function get_collection_params() {
return array(
'id' => array(
'description' => 'Current item id',
'type' => 'integer',
'min' => 1,
'default' => 1,
'sanitize_callback' => 'absint',
),
'slug' => array(
'description' => 'Page Slug',
'type' => 'string',
Expand Down
5 changes: 5 additions & 0 deletions includes/admin/class-caching.php
Original file line number Diff line number Diff line change
Expand Up @@ -113,6 +113,11 @@ public function maybe_serve_cached_response($query)

$this->set_path( $_SERVER['REQUEST_URI'] );

// Manually disabled for this page
if ( $this->is_page_caching_disabled( intval($this->get_page_id()) ) ) {
return;
}

if ( ! $this->is_instapage_published() || ! $this->is_page_cached() ) {
return;
}
Expand Down
16 changes: 16 additions & 0 deletions includes/admin/class-settings.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ public function __construct() {
$hooker->add_actions([
['admin_menu', $this, 'admin_menu', 100],
['admin_init', $this],
['admin_notices', $this],
]);

$hooker->add_filter( 'user_has_cap', $this, 'user_has_cap', 10, 4 );
Expand Down Expand Up @@ -111,6 +112,21 @@ public function admin_menu()
}


public function admin_notices() {

$page = isset( $_GET['page'] ) ? $_GET['page'] : false;
$status = self::get_option( 'instapage_cache_enabled', 'general' );

if ( 'instapage-cache' === $page && empty($status) )
{
printf(
'<div class="notice notice-warning is-dismissible"><p>%s</p></div>',
'Instapage Caching is disabled at the moment.'
);
}
}


/**
* Register settings sections and fields
*/
Expand Down
53 changes: 52 additions & 1 deletion includes/traits/helpers.php
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,59 @@ private function debug( $variable ) {
}



/**
* Get plugin option
* @param [type] $name [description]
* @param [type] $section [description]
* @return [type] [description]
*/
private function get_option( $name, $section ) {
return Settings_Page::get_option($name, $section);
}


/**
* Get List of all disabled pages
*/
private function get_disabled_pages()
{
return json_decode( get_option('codesoup_ilc_cache_disabled', wp_json_encode( array() )), true );
}


private function is_page_caching_disabled( int $page_id, $pages = array() )
{
return ( array_search($page_id, $this->get_disabled_pages()) !== false );
}

/**
* Disable caching
*/
private function disable_caching( int $page_id )
{
$pages = $this->get_disabled_pages();
$pages[] = $page_id;

update_option( 'codesoup_ilc_cache_disabled', wp_json_encode( array_unique($pages) ), false );

return $pages;
}


/**
* Enable caching
*/
private function enable_caching( int $page_id )
{
$pages = $this->get_disabled_pages();
$key = array_search($page_id, $pages);

if ($key !== false) {
unset($pages[$key]);
}

update_option( 'codesoup_ilc_cache_disabled', wp_json_encode( array_unique($pages) ), false );

return $pages;
}
}
2 changes: 1 addition & 1 deletion index.php
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
/**
* Plugin Name: Instapage Cache
* Description: Boost performance and reduce server load with Instapage Cache. This add-on for Instapage lets you easily manage and clear cache to speed up page load time.
* Version: 0.0.1
* Version: 0.0.2
* Requires Plugins: instapage
* Requires at least: 6.0
* Requires PHP: 8.2
Expand Down
24 changes: 12 additions & 12 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -49,32 +49,32 @@
"clean": "rimraf dist"
},
"devDependencies": {
"@babel/core": "^7.24.9",
"@babel/core": "^7.25.2",
"@babel/plugin-proposal-class-properties": "^7.18.6",
"@babel/preset-env": "^7.24.8",
"@babel/preset-env": "^7.25.3",
"@babel/preset-react": "^7.24.7",
"@wordpress/babel-preset-default": "^8.3.0",
"@wordpress/babel-preset-default": "^8.5.0",
"babel-loader": "^9.1.3",
"breakpoint-sass": "^3.0.0",
"clean-webpack-plugin": "^4.0.0",
"css-loader": "^7.1.2",
"cssnano": "^7.0.4",
"cssnano": "^7.0.5",
"dotenv": "^16.4.5",
"eslint": "^9.7.0",
"eslint": "^9.9.0",
"eslint-plugin-import": "^2.29.1",
"eslint-webpack-plugin": "^4.2.0",
"import-glob": "^1.5.0",
"jquery": "^3.7.1",
"mini-css-extract-plugin": "^2.9.0",
"postcss": "^8.4.39",
"postcss": "^8.4.41",
"postcss-loader": "^8.1.1",
"postcss-preset-env": "^9.6.0",
"postcss-preset-env": "^10.0.1",
"resolve-url-loader": "^5.0.0",
"rimraf": "^6.0.1",
"sass": "^1.77.8",
"sass-loader": "^15.0.0",
"sass-loader": "^16.0.0",
"style-loader": "^4.0.0",
"stylelint": "^16.7.0",
"stylelint": "^16.8.1",
"stylelint-config-property-sort-order-smacss": "^10.0.0",
"stylelint-config-standard-scss": "^13.1.0",
"stylelint-order": "^6.0.4",
Expand All @@ -86,11 +86,11 @@
"webpack-dev-server": "^5.0.4",
"webpack-merge": "^6.0.1",
"yargs": "~17.7.2",
"yarn-audit-fix": "^10.0.7"
"yarn-audit-fix": "^10.0.8"
},
"dependencies": {
"@wordpress/api-fetch": "^7.3.0",
"@wordpress/url": "^4.3.0",
"@wordpress/api-fetch": "^7.5.0",
"@wordpress/url": "^4.5.0",
"react": "^18.3.1",
"react-dom": "^18.3.1"
},
Expand Down
Loading

0 comments on commit 757eeba

Please sign in to comment.