Skip to content

Commit

Permalink
a4a client plugin: initial infrastructure (#36353)
Browse files Browse the repository at this point in the history
* a4a client plugin: initial infrastructure

* Fix naming

* Update lock file

* Add a basic test to make the linter happy

* Update lock file again

* Hide page from admin menu

* Add Phan config files

* Do not sync plugins

See pfunGA-of-p2#comment-812

* Revert "Do not sync plugins"

This reverts commit ff3304b.

See pfunGA-of-p2#comment-861

* Bump version

* Fix Phan warning

```
OOPError PhanNoopNew Unused result of new object creation expression in new Automattic_For_Agencies_Client() (this may be called for the side effects of the non-empty constructor or destructor)
```

* Update class reference

See #36353 (comment)

* Bring back plugins_loaded hook

See #36353 (comment)

* Update phan config

* changelog

* Revert move to plugins_loaded

It was causing issues with the deactivation process
  • Loading branch information
jeherve authored Mar 21, 2024
1 parent a966fea commit a48c77a
Show file tree
Hide file tree
Showing 39 changed files with 5,238 additions and 1 deletion.
91 changes: 91 additions & 0 deletions pnpm-lock.yaml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
Significance: patch
Type: changed

yUpdate Phan config.
2 changes: 1 addition & 1 deletion projects/packages/connection/src/class-package-version.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
*/
class Package_Version {

const PACKAGE_VERSION = '2.6.0';
const PACKAGE_VERSION = '2.6.1-alpha';

const PACKAGE_SLUG = 'connection';

Expand Down
17 changes: 17 additions & 0 deletions projects/plugins/automattic-for-agencies-client/.eslintrc.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
module.exports = {
extends: [ require.resolve( 'jetpack-js-tools/eslintrc/react' ) ],
parserOptions: {
babelOptions: {
configFile: require.resolve( './babel.config.js' ),
},
},
rules: {
// Enforce the use of the automattic-for-agencies-client textdomain.
'@wordpress/i18n-text-domain': [
'error',
{
allowedTextDomain: 'automattic-for-agencies-client',
},
],
},
};
38 changes: 38 additions & 0 deletions projects/plugins/automattic-for-agencies-client/.gitattributes
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# Files not needed to be distributed in the package.
.gitattributes export-ignore
.github/ export-ignore
package.json export-ignore

# Files to include in the mirror repo, but excluded via gitignore
# Remember to end all directories with `/**` to properly tag every file.
# /src/js/example.min.js production-include
build/** production-include
jetpack_vendor/** production-include
vendor/autoload.php production-include
vendor/autoload_packages.php production-include
vendor/automattic/** production-include
vendor/composer/** production-include
vendor/jetpack-autoloader/** production-include

# Files to exclude from the mirror repo, but included in the monorepo.
# Remember to end all directories with `/**` to properly tag every file.
.babelrc production-exclude
/.eslintrc.js production-exclude
.gitattributes production-exclude
.gitignore production-exclude
.phpcs.dir.xml production-exclude
babel.config.js production-exclude
build/**/*.js.map production-exclude
changelog/** production-exclude
composer.lock production-exclude
jest.config.js production-exclude
jest.setup.js production-exclude
package.json production-exclude
phpunit.xml.dist production-exclude
README.md production-exclude
src/js/** production-exclude
tests/** production-exclude
/vendor/automattic/jetpack-autoloader/** production-exclude
/vendor/automattic/jetpack-changelogger/** production-exclude
/vendor/automattic/jetpack-composer-plugin/** production-exclude
webpack.config.js production-exclude
5 changes: 5 additions & 0 deletions projects/plugins/automattic-for-agencies-client/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
vendor/
node_modules/
wordpress
build/
.cache/
17 changes: 17 additions & 0 deletions projects/plugins/automattic-for-agencies-client/.phan/baseline.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php
/**
* This is an automatically generated baseline for Phan issues.
* When Phan is invoked with --load-baseline=path/to/baseline.php,
* The pre-existing issues listed in this file won't be emitted.
*
* This file can be updated by invoking Phan with --save-baseline=path/to/baseline.php
* (can be combined with --load-baseline)
*/
return [
// This baseline has no suppressions
// Currently, file_suppressions and directory_suppressions are the only supported suppressions
'file_suppressions' => [
],
// 'directory_suppressions' => ['src/directory_name' => ['PhanIssueName1', 'PhanIssueName2']] can be manually added if needed.
// (directory_suppressions will currently be ignored by subsequent calls to --save-baseline, but may be preserved in future Phan releases)
];
13 changes: 13 additions & 0 deletions projects/plugins/automattic-for-agencies-client/.phan/config.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
<?php
/**
* This configuration will be read and overlaid on top of the
* default configuration. Command-line arguments will be applied
* after this file is read.
*
* @package automattic/jetpack-social
*/

// Require base config.
require __DIR__ . '/../../../../.phan/config.base.php';

return make_phan_config( dirname( __DIR__ ) );
24 changes: 24 additions & 0 deletions projects/plugins/automattic-for-agencies-client/.phpcs.dir.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,24 @@
<?xml version="1.0"?>
<ruleset>

<rule ref="WordPress.WP.I18n">
<properties>
<property name="text_domain" type="array">
<element value="automattic-for-agencies-client" />
</property>
</properties>
</rule>
<rule ref="Jetpack.Functions.I18n">
<properties>
<property name="text_domain" value="automattic-for-agencies-client" />
</properties>
</rule>

<rule ref="WordPress.Utils.I18nTextDomainFixer">
<properties>
<property name="old_text_domain" type="array" />
<property name="new_text_domain" value="automattic-for-agencies-client" />
</properties>
</rule>

</ruleset>
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# WordPress.org Assets

This directory is intended to hold assets meant for w.org plugins SVN.

There is no auto-deployment of these assets, so once you make changes, please ping the plugin's team or ask Crew to deploy them.
6 changes: 6 additions & 0 deletions projects/plugins/automattic-for-agencies-client/CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
# Changelog

All notable changes to this project will be documented in this file.

The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/)
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
20 changes: 20 additions & 0 deletions projects/plugins/automattic-for-agencies-client/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Automattic For Agencies Client

Automattic For Agencies Client plugin

## How to install Automattic For Agencies Client

### Installation From Git Repo

## Contribute

## Get Help

## Security

Need to report a security vulnerability? Go to [https://automattic.com/security/](https://automattic.com/security/) or directly to our security bug bounty site [https://hackerone.com/automattic](https://hackerone.com/automattic).

## License

Automattic For Agencies Client is licensed under [GNU General Public License v2 (or later)](./LICENSE.txt)

Original file line number Diff line number Diff line change
@@ -0,0 +1,121 @@
<?php
/**
*
* Plugin Name: Automattic for Agencies Client
* Plugin URI: https://wordpress.org/plugins/automattic-for-agencies-client
* Description: Easily connect your clients sites to the Automattic for Agencies portal and enable portal features like plugin updates, downtime monitoring, and more..
* Version: 0.1.0-alpha
* Author: Automattic
* Author URI: https://jetpack.com/
* License: GPLv2 or later
* Text Domain: automattic-for-agencies-client
*
* @package automattic/automattic-for-agencies-client
*/

/*
This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/

if ( ! defined( 'ABSPATH' ) ) {
exit;
}

define( 'AUTOMATTIC_FOR_AGENCIES_CLIENT_DIR', plugin_dir_path( __FILE__ ) );
define( 'AUTOMATTIC_FOR_AGENCIES_CLIENT_ROOT_FILE', __FILE__ );
define( 'AUTOMATTIC_FOR_AGENCIES_CLIENT_ROOT_FILE_RELATIVE_PATH', plugin_basename( __FILE__ ) );
define( 'AUTOMATTIC_FOR_AGENCIES_CLIENT_SLUG', 'automattic-for-agencies-client' );
define( 'AUTOMATTIC_FOR_AGENCIES_CLIENT_NAME', 'Automattic for Agencies Client' );
define( 'AUTOMATTIC_FOR_AGENCIES_CLIENT_URI', 'https://jetpack.com/automattic-for-agencies-client' );
define( 'AUTOMATTIC_FOR_AGENCIES_CLIENT_FOLDER', dirname( plugin_basename( __FILE__ ) ) );

// Jetpack Autoloader.
$jetpack_autoloader = AUTOMATTIC_FOR_AGENCIES_CLIENT_DIR . 'vendor/autoload_packages.php';
if ( is_readable( $jetpack_autoloader ) ) {
require_once $jetpack_autoloader;
if ( method_exists( \Automattic\Jetpack\Assets::class, 'alias_textdomains_from_file' ) ) {
\Automattic\Jetpack\Assets::alias_textdomains_from_file( AUTOMATTIC_FOR_AGENCIES_CLIENT_DIR . 'jetpack_vendor/i18n-map.php' );
}
} else { // Something very unexpected. Error out gently with an admin_notice and exit loading.
if ( defined( 'WP_DEBUG' ) && WP_DEBUG ) {
error_log( // phpcs:ignore WordPress.PHP.DevelopmentFunctions.error_log_error_log
__( 'Error loading autoloader file for Automattic For Agencies Client plugin', 'automattic-for-agencies-client' )
);
}

add_action(
'admin_notices',
function () {
?>
<div class="notice notice-error is-dismissible">
<p>
<?php
printf(
wp_kses(
/* translators: Placeholder is a link to a support document. */
__( 'Your installation of Automattic For Agencies Client is incomplete. If you installed Automattic For Agencies Client from GitHub, please refer to <a href="%1$s" target="_blank" rel="noopener noreferrer">this document</a> to set up your development environment. Automattic For Agencies Client must have Composer dependencies installed and built via the build command.', 'automattic-for-agencies-client' ),
array(
'a' => array(
'href' => array(),
'target' => array(),
'rel' => array(),
),
)
),
'https://github.com/Automattic/jetpack/blob/trunk/docs/development-environment.md#building-your-project'
);
?>
</p>
</div>
<?php
}
);

return;
}

// Add "Settings" link to plugins page.
add_filter(
'plugin_action_links_' . AUTOMATTIC_FOR_AGENCIES_CLIENT_FOLDER . '/automattic-for-agencies-client.php',
function ( $actions ) {
$settings_link = '<a href="' . esc_url( admin_url( 'options-general.php?page=' . AUTOMATTIC_FOR_AGENCIES_CLIENT_SLUG ) ) . '">' . __( 'Settings', 'automattic-for-agencies-client' ) . '</a>';
array_unshift( $actions, $settings_link );

return $actions;
}
);

// Redirect to plugin page when the plugin is activated.
add_action( 'activated_plugin', 'jetpack_starter_plugin_activation' );

/**
* Redirects to plugin page when the plugin is activated
*
* @param string $plugin Path to the plugin file relative to the plugins directory.
*/
function jetpack_starter_plugin_activation( $plugin ) {
if (
AUTOMATTIC_FOR_AGENCIES_CLIENT_ROOT_FILE_RELATIVE_PATH === $plugin &&
\Automattic\Jetpack\Plugins_Installer::is_current_request_activating_plugin_from_plugins_screen( AUTOMATTIC_FOR_AGENCIES_CLIENT_ROOT_FILE_RELATIVE_PATH )
) {
wp_safe_redirect( esc_url( admin_url( 'options-general.php?page=' . AUTOMATTIC_FOR_AGENCIES_CLIENT_SLUG ) ) );
exit;
}
}

register_deactivation_hook( __FILE__, array( 'Automattic_For_Agencies_Client', 'plugin_deactivation' ) );

// Initialize the plugin's main class.
Automattic_For_Agencies_Client::init();
10 changes: 10 additions & 0 deletions projects/plugins/automattic-for-agencies-client/babel.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
const config = {
presets: [
[
'@automattic/jetpack-webpack-config/babel/preset',
{ pluginReplaceTextdomain: { textdomain: 'automattic-for-agencies-client' } },
],
],
};

module.exports = config;
Empty file.
Loading

0 comments on commit a48c77a

Please sign in to comment.