Skip to content

Commit 5265cbf

Browse files
authored
Merge pull request #3 from haruncpi/dev
v1.0.3
2 parents af2de58 + ff26895 commit 5265cbf

File tree

6 files changed

+62
-22
lines changed

6 files changed

+62
-22
lines changed

ajax.php

Lines changed: 6 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
* Plugin Name: Ajax
44
* Description: Ajax request testing
55
* Author: haruncpi
6-
* Version: 1.0.1
6+
* Version: 1.0.3
77
* Author URI: https://github.com/haruncpi
88
* Requires PHP: 7.4
99
* Requires at least: 5.3
@@ -13,13 +13,10 @@
1313
* @package Ajax
1414
*/
1515

16-
use Ajax\Plugin;
16+
if ( ! defined( 'ABSPATH' ) ) {
17+
exit;
18+
}
1719

18-
require_once __DIR__ . '/vendor/autoload.php';
20+
require_once __DIR__ . '/bootstrap.php';
1921

20-
define( 'AJAX_VERSION', '1.0.1' );
21-
define( 'AJAX_FILE', __DIR__ );
22-
define( 'AJAX_DIR', plugin_dir_path( __FILE__ ) );
23-
define( 'AJAX_URL', plugin_dir_url( __FILE__ ) );
24-
25-
Plugin::get_instance();
22+
Ajax\Plugin::get_instance();

bootstrap.php

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
<?php
2+
/**
3+
* Plugin bootstrap
4+
*
5+
* @package Ajax
6+
*/
7+
8+
if ( ! defined( 'ABSPATH' ) ) {
9+
exit;
10+
}
11+
12+
require_once __DIR__ . '/vendor/autoload.php';
13+
14+
if ( ! function_exists( 'get_plugin_data' ) ) {
15+
require_once ABSPATH . 'wp-admin/includes/plugin.php';
16+
}
17+
18+
define( 'AJAX_FILE', __DIR__ . '/ajax.php' );
19+
define( 'AJAX_VERSION', get_plugin_data( AJAX_FILE )['Version'] );
20+
define( 'AJAX_DIR', plugin_dir_path( AJAX_FILE ) );
21+
define( 'AJAX_URL', plugin_dir_url( AJAX_FILE ) );

gulpfile.js

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,7 @@ try {
1717

1818
const zipName = `${pluginName}-${versionNumber}.zip`;
1919
const buildDest = './build';
20+
2021
const buildFiles = [
2122
'./**/*',
2223
'!./build/**',
@@ -71,7 +72,7 @@ const makePod = (cb) => {
7172
}
7273
}
7374

74-
const build = cb => src(buildFiles).pipe(dest(buildDest))
75+
const build = cb => src(buildFiles).pipe(dest(`${buildDest}/${pluginName}`))
7576
const buildZip = cb => src(`${buildDest}/**/*`).pipe(zip(zipName)).pipe(dest('./'))
7677

7778

src/Plugin.php

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,10 @@ private function bootstrap() {
5555
new Ajax();
5656

5757
$config = array(
58-
'update_url' => 'https://raw.githubusercontent.com/haruncpi/wp-ajax/master/src/Updater/plugin.json',
59-
'plugin_file' => AJAX_FILE,
60-
'current_version' => AJAX_VERSION,
58+
'plugin_file' => AJAX_FILE,
59+
'update_url' => 'https://raw.githubusercontent.com/haruncpi/wp-ajax/master/src/Updater/plugin.json',
6160
);
6261

63-
Updater::setup( $config );
62+
Updater::configure( $config );
6463
}
6564
}

src/Updater/Updater.php

Lines changed: 26 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
<?php
22
/**
33
* Manage Plugin Update
4+
* Plugin update transient: _site_transient_update_plugins
5+
* Theme update transient: _site_transient_update_themes
46
*
57
* @package Ajax
68
* @author Harun <harun.cox@gmail.com>
@@ -63,9 +65,8 @@ class Updater {
6365
*/
6466
private function __construct( $config ) {
6567
$required_keys = array(
66-
'update_url',
6768
'plugin_file',
68-
'current_version',
69+
'update_url',
6970
);
7071

7172
foreach ( $required_keys as $key ) {
@@ -74,9 +75,21 @@ private function __construct( $config ) {
7475
}
7576
}
7677

78+
$plugin_file = $config['plugin_file'];
79+
80+
if ( ! is_file( $plugin_file ) ) {
81+
wp_die( esc_html( "Plugin file not found: $plugin_file" ) );
82+
}
83+
84+
if ( ! function_exists( 'get_plugin_data' ) ) {
85+
require_once ABSPATH . 'wp-admin/includes/plugin.php';
86+
}
87+
88+
$plugin_data = get_plugin_data( $plugin_file );
89+
7790
$this->update_url = $config['update_url'];
7891
$this->plugin_slug = plugin_basename( $config['plugin_file'] );
79-
$this->version = $config['current_version'];
92+
$this->version = $plugin_data['Version'];
8093
$this->cache_key = "{$this->plugin_slug}_update";
8194
$this->cache_allowed = true;
8295

@@ -91,7 +104,7 @@ private function __construct( $config ) {
91104
*
92105
* @return self
93106
*/
94-
public static function setup( $config ) {
107+
public static function configure( $config ) {
95108
if ( isset( self::$instance ) ) {
96109
return self::$instance;
97110
}
@@ -138,6 +151,15 @@ public function request() {
138151

139152
}
140153

154+
/**
155+
* Clear request cache.
156+
*
157+
* @return void
158+
*/
159+
public function clear_request_cache() {
160+
delete_transient( $this->cache_key );
161+
}
162+
141163
/**
142164
* Plugin info
143165
*

src/Updater/plugin.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,14 @@
11
{
22
"name" : "Ajax",
33
"slug" : "ajax",
4-
"version" : "1.0.1",
4+
"version" : "1.0.3",
5+
"download_url" : "https://github.com/haruncpi/wp-ajax/releases/download/v1.0.3/ajax-1.0.3.zip",
56
"author" : "<a href='https://github.com/haruncpi'>Harun</a>",
67
"author_profile" : "https://github.com/haruncpi",
7-
"download_url" : "https://github.com/haruncpi/wp-ajax/releases/download/v1.0.1/ajax-1.0.1.zip",
8-
"requires" : "3.0",
8+
"requires" : "5.0",
99
"tested" : "6.6",
1010
"requires_php" : "7.4",
11-
"last_updated" : "2024-08-09 12:00:00",
11+
"last_updated" : "2024-08-14 00:00:00",
1212
"sections" : {
1313
"description" : "This simple plugin does nothing, only gets updates from a custom server",
1414
"installation" : "Click the activate button and that's it.",

0 commit comments

Comments
 (0)