Use Composer autoload feature
* Use Composer autoload feature * Update dependencies * Remove now unneeded 'classmap' autoload * Use Mozilla namespace * Update 'composer install' command to use --optimize-autoloader argument
This commit is contained in:
Родитель
dc917ca3a0
Коммит
5d17a04c19
|
@ -12,7 +12,7 @@ First clone the repository.
|
|||
Once inside the repository you will need [composer](https://getcomposer.org) and [bower](http://bower.io/) installed. Go to the folder `wp-add-to-homescreen` inside the repository folder and run:
|
||||
|
||||
```
|
||||
$ composer install
|
||||
$ composer install --optimize-autoloader
|
||||
$ bower install
|
||||
```
|
||||
|
||||
|
|
|
@ -2,7 +2,6 @@
|
|||
|
||||
include_once(plugin_dir_path(__FILE__) . 'class-wp-add-to-homescreen-stats.php');
|
||||
include_once(plugin_dir_path(__FILE__) . 'class-wp-add-to-homescreen-options.php');
|
||||
include_once(plugin_dir_path(__FILE__) . 'vendor/marco-c/wp-web-app-manifest-generator/WebAppManifestGenerator.php');
|
||||
|
||||
// Based on: https://codex.wordpress.org/Creating_Options_Pages#Example_.232
|
||||
class WP_Add_To_Homescreen_Admin {
|
||||
|
@ -148,7 +147,7 @@ class WP_Add_To_Homescreen_Admin {
|
|||
return $current_icon;
|
||||
}
|
||||
if ($current_icon !== $new_icon) {
|
||||
WebAppManifestGenerator::getInstance()->set_field('icons', array(
|
||||
Mozilla\WebAppManifestGenerator::getInstance()->set_field('icons', array(
|
||||
array(
|
||||
'src' => $new_icon['url'],
|
||||
'sizes' => '144x144',
|
||||
|
@ -177,7 +176,7 @@ class WP_Add_To_Homescreen_Admin {
|
|||
if ('title' === $new_app_name['type']) {
|
||||
$new_app_name['value'] = get_bloginfo('name');
|
||||
if ($current_app_name !== $new_app_name) {
|
||||
WebAppManifestGenerator::getInstance()->set_field('short_name', $new_app_name['value']);
|
||||
Mozilla\WebAppManifestGenerator::getInstance()->set_field('short_name', $new_app_name['value']);
|
||||
}
|
||||
return $new_app_name;
|
||||
}
|
||||
|
@ -193,7 +192,7 @@ class WP_Add_To_Homescreen_Admin {
|
|||
}
|
||||
|
||||
if ($current_app_name !== $new_app_name) {
|
||||
WebAppManifestGenerator::getInstance()->set_field('short_name', $new_app_name['value']);
|
||||
Mozilla\WebAppManifestGenerator::getInstance()->set_field('short_name', $new_app_name['value']);
|
||||
}
|
||||
return $new_app_name;
|
||||
}
|
||||
|
|
|
@ -2,8 +2,6 @@
|
|||
|
||||
include_once(plugin_dir_path(__FILE__) . 'class-wp-add-to-homescreen-options.php');
|
||||
include_once(plugin_dir_path(__FILE__) . 'class-wp-add-to-homescreen-stats.php');
|
||||
include_once(plugin_dir_path(__FILE__) . 'vendor/marco-c/wp-web-app-manifest-generator/WebAppManifestGenerator.php');
|
||||
include_once(plugin_dir_path(__FILE__) . 'vendor/mozilla/wp-sw-manager/class-wp-sw-manager.php');
|
||||
|
||||
class WP_Add_To_Homescreen_Plugin {
|
||||
const STATS_ACTION = 'stats';
|
||||
|
@ -43,7 +41,7 @@ class WP_Add_To_Homescreen_Plugin {
|
|||
register_activation_hook($plugin_main_file, array($this, 'activate'));
|
||||
register_deactivation_hook($plugin_main_file, array($this, 'deactivate'));
|
||||
|
||||
WP_Serve_File::getInstance()->add_file('add2home.svg', array($this, 'generate_add2home_icon'));
|
||||
Mozilla\WP_Serve_File::getInstance()->add_file('add2home.svg', array($this, 'generate_add2home_icon'));
|
||||
}
|
||||
|
||||
private function set_urls() {
|
||||
|
@ -62,7 +60,7 @@ class WP_Add_To_Homescreen_Plugin {
|
|||
|
||||
private function generate_sw() {
|
||||
// An empty SW only to meet Chrome add to homescreen banner requirements.
|
||||
WP_SW_Manager::get_manager()->sw()->add_content(function () { });
|
||||
Mozilla\WP_SW_Manager::get_manager()->sw()->add_content(function () { });
|
||||
}
|
||||
|
||||
public function enqueue_assets() {
|
||||
|
@ -83,7 +81,7 @@ class WP_Add_To_Homescreen_Plugin {
|
|||
'title' => sprintf(__('Add %s to home screen', 'add-to-homescreen'), $app_name['value']),
|
||||
'dismissText' => __('Got it!', 'add-to-homescreen'),
|
||||
'statsEndPoint' => admin_url('/admin-ajax.php?action=' . self::STATS_ACTION),
|
||||
'add2homeIconUrl' => WP_Serve_File::getInstance()->get_relative_to_host_root_url('add2home.svg')
|
||||
'add2homeIconUrl' => Mozilla\WP_Serve_File::getInstance()->get_relative_to_host_root_url('add2home.svg')
|
||||
));
|
||||
wp_enqueue_script('add-to-homescreen');
|
||||
wp_enqueue_script(
|
||||
|
@ -108,7 +106,7 @@ class WP_Add_To_Homescreen_Plugin {
|
|||
|
||||
public function activate() {
|
||||
$this->generate_manifest();
|
||||
WP_Serve_File::getInstance()->invalidate_files(array('add2home.svg'));
|
||||
Mozilla\WP_Serve_File::getInstance()->invalidate_files(array('add2home.svg'));
|
||||
}
|
||||
|
||||
public function deactivate() {
|
||||
|
@ -119,7 +117,7 @@ class WP_Add_To_Homescreen_Plugin {
|
|||
$icon = $this->options->get('icon');
|
||||
$app_name = $this->options->get('app-name');
|
||||
|
||||
$manifest = WebAppManifestGenerator::getInstance();
|
||||
$manifest = Mozilla\WebAppManifestGenerator::getInstance();
|
||||
$manifest->set_field('name', get_bloginfo('name'));
|
||||
$manifest->set_field('short_name', $app_name['value']);
|
||||
$manifest->set_field('display', 'standalone');
|
||||
|
@ -135,7 +133,7 @@ class WP_Add_To_Homescreen_Plugin {
|
|||
}
|
||||
|
||||
private function remove_manifest() {
|
||||
$manifest = WebAppManifestGenerator::getInstance();
|
||||
$manifest = Mozilla\WebAppManifestGenerator::getInstance();
|
||||
$fields = array('name', 'short_name', 'display', 'orientation', 'start_url', 'icons');
|
||||
foreach ($fields as $field) {
|
||||
$manifest->set_field($field, NULL);
|
||||
|
@ -153,4 +151,4 @@ class WP_Add_To_Homescreen_Plugin {
|
|||
|
||||
}
|
||||
|
||||
?>
|
||||
?>
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
}
|
||||
],
|
||||
"require": {
|
||||
"marco-c/wp_serve_file": "dev-master",
|
||||
"marco-c/wp_serve_file": "dev-master",
|
||||
"marco-c/wp-web-app-manifest-generator": "dev-master",
|
||||
"mozilla/wp-sw-manager": "dev-master"
|
||||
}
|
||||
|
|
|
@ -4,7 +4,7 @@
|
|||
"Read more about it at https://getcomposer.org/doc/01-basic-usage.md#composer-lock-the-lock-file",
|
||||
"This file is @generated automatically"
|
||||
],
|
||||
"hash": "1bf2f6f91c01a11826e97050181b1ba8",
|
||||
"hash": "cf3f13b39b316c2a8ad55e4b4ef3aaf8",
|
||||
"packages": [
|
||||
{
|
||||
"name": "marco-c/wp-web-app-manifest-generator",
|
||||
|
@ -12,18 +12,23 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/marco-c/wp-web-app-manifest-generator.git",
|
||||
"reference": "8d8dfd2cc7fdfc4e7c114fac6a55e13924a73f76"
|
||||
"reference": "df594f6b6ba60030008be0fc48174bec3899ffd1"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/marco-c/wp-web-app-manifest-generator/zipball/8d8dfd2cc7fdfc4e7c114fac6a55e13924a73f76",
|
||||
"reference": "8d8dfd2cc7fdfc4e7c114fac6a55e13924a73f76",
|
||||
"url": "https://api.github.com/repos/marco-c/wp-web-app-manifest-generator/zipball/df594f6b6ba60030008be0fc48174bec3899ffd1",
|
||||
"reference": "df594f6b6ba60030008be0fc48174bec3899ffd1",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"marco-c/wp_serve_file": "dev-master"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Mozilla\\": ""
|
||||
}
|
||||
},
|
||||
"license": [
|
||||
"GPLv2"
|
||||
],
|
||||
|
@ -38,7 +43,7 @@
|
|||
"source": "https://github.com/marco-c/wp-web-app-manifest-generator/tree/master",
|
||||
"issues": "https://github.com/marco-c/wp-web-app-manifest-generator/issues"
|
||||
},
|
||||
"time": "2016-04-04 12:15:18"
|
||||
"time": "2016-04-04 16:57:49"
|
||||
},
|
||||
{
|
||||
"name": "marco-c/wp_serve_file",
|
||||
|
@ -46,15 +51,20 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/marco-c/WP_Serve_File.git",
|
||||
"reference": "3240b22d9399fd12f2efb754e34c8bcf008f8300"
|
||||
"reference": "4b1c0d812375e609d31342118cb886e12a235b9f"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/marco-c/WP_Serve_File/zipball/3240b22d9399fd12f2efb754e34c8bcf008f8300",
|
||||
"reference": "3240b22d9399fd12f2efb754e34c8bcf008f8300",
|
||||
"url": "https://api.github.com/repos/marco-c/WP_Serve_File/zipball/4b1c0d812375e609d31342118cb886e12a235b9f",
|
||||
"reference": "4b1c0d812375e609d31342118cb886e12a235b9f",
|
||||
"shasum": ""
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Mozilla\\": ""
|
||||
}
|
||||
},
|
||||
"notification-url": "https://packagist.org/downloads/",
|
||||
"license": [
|
||||
"GPLv2"
|
||||
|
@ -66,7 +76,7 @@
|
|||
}
|
||||
],
|
||||
"description": "Class to serve dynamic files in WordPress with performance in mind.",
|
||||
"time": "2016-04-04 10:07:44"
|
||||
"time": "2016-04-04 19:09:54"
|
||||
},
|
||||
{
|
||||
"name": "mozilla/wp-sw-manager",
|
||||
|
@ -74,15 +84,23 @@
|
|||
"source": {
|
||||
"type": "git",
|
||||
"url": "https://github.com/mozilla/wp-sw-manager.git",
|
||||
"reference": "5d248ab5590b6e83ff23d7201d5b5f34b40c429f"
|
||||
"reference": "cc42eee94c4e1ba1a77890500b6eb02eb52798bd"
|
||||
},
|
||||
"dist": {
|
||||
"type": "zip",
|
||||
"url": "https://api.github.com/repos/mozilla/wp-sw-manager/zipball/5d248ab5590b6e83ff23d7201d5b5f34b40c429f",
|
||||
"reference": "5d248ab5590b6e83ff23d7201d5b5f34b40c429f",
|
||||
"url": "https://api.github.com/repos/mozilla/wp-sw-manager/zipball/cc42eee94c4e1ba1a77890500b6eb02eb52798bd",
|
||||
"reference": "cc42eee94c4e1ba1a77890500b6eb02eb52798bd",
|
||||
"shasum": ""
|
||||
},
|
||||
"require": {
|
||||
"marco-c/wp_serve_file": "dev-master"
|
||||
},
|
||||
"type": "library",
|
||||
"autoload": {
|
||||
"psr-4": {
|
||||
"Mozilla\\": ""
|
||||
}
|
||||
},
|
||||
"license": [
|
||||
"GPLv2"
|
||||
],
|
||||
|
@ -97,7 +115,7 @@
|
|||
"source": "https://github.com/mozilla/wp-sw-manager/tree/master",
|
||||
"issues": "https://github.com/mozilla/wp-sw-manager/issues"
|
||||
},
|
||||
"time": "2016-03-14 17:17:15"
|
||||
"time": "2016-04-06 12:37:44"
|
||||
}
|
||||
],
|
||||
"packages-dev": [],
|
||||
|
|
|
@ -10,6 +10,8 @@ License: GPLv2 or later
|
|||
Text Domain: add-to-homescreen
|
||||
*/
|
||||
|
||||
require_once(plugin_dir_path(__FILE__) . 'vendor/autoload.php');
|
||||
|
||||
load_plugin_textdomain('add-to-homescreen', false, dirname(plugin_basename(__FILE__)) . '/lang');
|
||||
|
||||
include_once(plugin_dir_path(__FILE__) . 'class-wp-add-to-homescreen-plugin.php');
|
||||
|
|
Загрузка…
Ссылка в новой задаче