Skip to content

Commit

Permalink
psr autoload
Browse files Browse the repository at this point in the history
  • Loading branch information
erikyo committed Oct 13, 2023
1 parent bc2a140 commit def47ed
Show file tree
Hide file tree
Showing 21 changed files with 169 additions and 94 deletions.
7 changes: 6 additions & 1 deletion admin/admin.php → admin/CF7_AntiSpam_Admin_Core.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php

namespace CF7_AntiSpam\Admin;
use CF7_AntiSpam\Core\CF7_Antispam_Geoip;
use WP_Query;

/**
* The admin-specific functionality of the plugin.
*
Expand All @@ -13,7 +18,7 @@
/**
* It creates a class called CF7_AntiSpam_Admin.
*/
class CF7_AntiSpam_Admin {
class CF7_AntiSpam_Admin_Core {

/**
* The ID of this plugin.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php

namespace CF7_AntiSpam\Admin;

use CF7_AntiSpam\Core\CF7_AntiSpam;

/**
* The plugin settings.
*
Expand Down Expand Up @@ -66,15 +71,15 @@ public function cf7a_options_init() {
array( $this, 'cf7a_print_section_main_subtitle' ),
'cf7a-settings'
);

/* Section Bot Fingerprint */
add_settings_section(
'cf7a_auto_blacklist',
__( 'Ban automatically spammers', 'cf7-antispam' ),
array( $this, 'cf7a_print_section_auto_blacklist' ),
'cf7a-settings'
);

/* Settings autostore_bad_ip */
add_settings_field(
'autostore_bad_ip',
Expand Down Expand Up @@ -974,6 +979,7 @@ private function cf7a_input_cron_schedule( $input, $input_name, $cron_task, $sch
* @return array $options sanitized
*/
public function cf7a_sanitize_options( $input ) {
$new_input['cf7a_enabled'] = isset( $input['cf7a_enabled'] ) ? 1 : 0;

/* get the existing options */
$new_input = $this->options;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,9 @@
<?php

namespace CF7_AntiSpam\Admin;

use CF7_AntiSpam\Core\CF7_AntiSpam;

/**
* The plugin notices and ui stuff.
*
Expand Down
8 changes: 8 additions & 0 deletions admin/admin-tools.php → admin/CF7_AntiSpam_Admin_Tools.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,12 @@
<?php

namespace CF7_AntiSpam\Admin;

use CF7_AntiSpam\Core\CF7_AntiSpam;
use CF7_AntiSpam\Core\CF7_AntiSpam_Filters;
use CF7_AntiSpam\Core\CF7_AntiSpam_Flamingo;
use CF7_AntiSpam\Core\CF7_AntiSpam_Uninstaller;

/**
* The plugin admin tools
*
Expand Down
42 changes: 14 additions & 28 deletions cf7-antispam.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,13 @@
*/

/* If this file is called directly, abort. */

use CF7_AntiSpam\Core\CF7_AntiSpam;
use CF7_AntiSpam\Core\CF7_AntiSpam_Activator;
use CF7_AntiSpam\Core\CF7_AntiSpam_Deactivator;
use CF7_AntiSpam\Core\WPCF7_Service;
use CF7_AntiSpam\Core\CF7_AntiSpam_Uninstaller;

if ( ! defined( 'WPINC' ) ) {
die;
}
Expand Down Expand Up @@ -62,13 +69,12 @@
/**
* CF7-AntiSpam functions
*/
require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-functions.php';
require_once CF7ANTISPAM_PLUGIN_DIR . '/core/functions.php';

/**
* The code that runs during plugin activation.
*/
function activate_cf7_antispam( $network_wide ) {
require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-activator.php';
CF7_AntiSpam_Activator::on_activate( $network_wide );
}
register_activation_hook( CF7ANTISPAM_PLUGIN, 'activate_cf7_antispam' );
Expand All @@ -82,7 +88,6 @@ function activate_cf7_antispam( $network_wide ) {
*/
function on_create_blog( $blog_id ) {
if ( is_plugin_active_for_network( 'cf7-antispam/cf7-antispam.php' ) ) {
require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-activator.php';
switch_to_blog( $blog_id );
CF7_AntiSpam_Activator::activate();
restore_current_blog();
Expand All @@ -109,7 +114,6 @@ function on_delete_blog( $tables ) {
* The code that runs during plugin deactivation.
*/
function deactivate_cf7_antispam() {
require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-deactivator.php';
CF7_AntiSpam_Deactivator::deactivate();
}
register_deactivation_hook( CF7ANTISPAM_PLUGIN, 'deactivate_cf7_antispam' );
Expand All @@ -118,51 +122,33 @@ function deactivate_cf7_antispam() {
* The code that runs during plugin un-installation.
*/
function uninstall_cf7_antispam() {
require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-uninstall.php';
CF7_AntiSpam_Uninstaller::uninstall();
}
register_uninstall_hook( CF7ANTISPAM_PLUGIN, 'uninstall_cf7_antispam' );


/**
* The core plugin class that is used to define internationalization,
* admin-specific hooks, and public-facing site hooks.
*/
require CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-core.php';

/**
* Initialize the plugin once all other plugins have finished loading.
*/


/**
* call the integration action to mount our plugin as a component
* Call the integration action to mount our plugin as a component
* into the intefration page
*/

function cf7_antispam_register_service() {
require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/service.php';
require_once CF7ANTISPAM_PLUGIN_DIR . '/core/WPCF7_Service.php';
$integration = WPCF7_Integration::get_instance();
$integration->add_service(
'cf7-antispam',
WPCF7_Antispam::get_instance()
\CF7_AntiSpam\Core\WPCF7_Antispam::get_instance()
);

}
add_action( 'wpcf7_init', 'cf7_antispam_register_service', 1, 0 );




function run_cf7a() {
$enabled = get_option( 'cf7a_options' );
if ( $enabled && $enabled['cf7a_enable'] === true ) {
if ( $enabled && ! empty( $enabled['cf7a_enable'] ) ) {
$cf7a = new CF7_AntiSpam();
$cf7a->run();
}

}
add_action( 'init', 'run_cf7a', 11, 0 );




19 changes: 15 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,9 @@
"wp-coding-standards/wpcs": "^2.3",
"automattic/vipwpcs": "^2.3",
"phpcompatibility/phpcompatibility-wp": "*",
"phpunit/phpunit": "^8|^9",
"phpunit/phpunit": "^9.6.13",
"wp-phpunit/wp-phpunit": "^5.9.5",
"yoast/phpunit-polyfills": "^1.0",
"yoast/phpunit-polyfills": "^1.1",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7"
},
"require": {
Expand All @@ -30,7 +30,7 @@
},
"scripts": {
"PHPCS": "vendor/bin/phpcbf --standard=phpcs.ruleset.xml -s --report=full,summary,source",
"test": "vendor/bin/phpunit -c phpunit.xml.dist --verbose",
"test": "vendor/bin/phpunit -c phpunit.xml.dist",
"test-multisite": "WP_MULTISITE=1 vendor/bin/phpunit -c tests/multisite.xml --verbose"
},
"minimum-stability": "dev",
Expand All @@ -55,5 +55,16 @@
"dealerdirect/phpcodesniffer-composer-installer": true,
"phpstan/extension-installer": true
}
}
},
"autoload": {
"psr-4": {
"CF7_AntiSpam\\Core\\": "core/",
"CF7_AntiSpam\\Admin\\": "admin/"
}
},
"autoload-dev": {
"psr-4": {
"CF7_AntiSpam\\Tests\\": "tests/"
}
}
}
78 changes: 43 additions & 35 deletions includes/cf7a-core.php → core/CF7_AntiSpam.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

namespace CF7_AntiSpam\Core;

/**
* The core plugin class.
*
Expand All @@ -14,6 +17,11 @@
* @author Codekraft Studio <[email protected]>
*/

namespace CF7_AntiSpam\Core;

use CF7_AntiSpam\Admin\CF7_AntiSpam_Admin_Core;
use CF7_AntiSpam\Admin\CF7_AntiSpam_Admin_Tools;

/**
* It sets the version, plugin name, and options. It loads
* the dependencies, sets the locale, updates the plugin, and loads the admin and frontend areas
Expand Down Expand Up @@ -128,40 +136,40 @@ protected function update() {
*/
private function load_dependencies() {

/**
* The class responsible for orchestrating the actions and filters of the
* core plugin.
*/
require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-loader.php';

/**
* The class responsible for defining internationalization functionality
* of the plugin.
*/
require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-i18n.php';

/**
* The class responsible for defining frontend functionality
* of the plugin.
*/
require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-frontend.php';

/**
* The classes responsible for defining antispam functionality and the related filters
* of the plugin.
*/
require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-antispam-filters.php';
require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-antispam-geoip.php';
require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-antispam-flamingo.php';
require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-antispam-b8.php';

/**
* The classes responsible for defining admin backend functionality
*/
require_once CF7ANTISPAM_PLUGIN_DIR . '/admin/admin-customizations.php';
require_once CF7ANTISPAM_PLUGIN_DIR . '/admin/admin-display.php';
require_once CF7ANTISPAM_PLUGIN_DIR . '/admin/admin-tools.php';
require_once CF7ANTISPAM_PLUGIN_DIR . '/admin/admin.php';
// /**
// * The class responsible for orchestrating the actions and filters of the
// * core plugin.
// */
// require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-loader.php';
//
// /**
// * The class responsible for defining internationalization functionality
// * of the plugin.
// */
// require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-i18n.php';
//
// /**
// * The class responsible for defining frontend functionality
// * of the plugin.
// */
// require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-frontend.php';
//
// /**
// * The classes responsible for defining antispam functionality and the related filters
// * of the plugin.
// */
// require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-antispam-filters.php';
// require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-antispam-geoip.php';
// require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-antispam-flamingo.php';
// require_once CF7ANTISPAM_PLUGIN_DIR . '/includes/cf7a-antispam-b8.php';
//
// /**
// * The classes responsible for defining admin backend functionality
// */
// require_once CF7ANTISPAM_PLUGIN_DIR . '/admin/admin-customizations.php';
// require_once CF7ANTISPAM_PLUGIN_DIR . '/admin/admin-display.php';
// require_once CF7ANTISPAM_PLUGIN_DIR . '/admin/admin-tools.php';
// require_once CF7ANTISPAM_PLUGIN_DIR . '/admin/admin.php';

$this->loader = new CF7_AntiSpam_Loader();
}
Expand Down Expand Up @@ -236,7 +244,7 @@ private function load_admin() {
add_action( 'admin_init', array( $tools, 'cf7a_handle_actions' ), 1 );

/* the admin area */
$plugin_admin = new CF7_AntiSpam_Admin( $this->get_plugin_name(), $this->get_version() );
$plugin_admin = new CF7_AntiSpam_Admin_Core( $this->get_plugin_name(), $this->get_version() );

/* add the admin menu */
$this->loader->add_action( 'admin_menu', $plugin_admin, 'cf7a_admin_menu' );
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

namespace CF7_AntiSpam\Core;

/**
* Fired during plugin activation.
*
Expand Down
3 changes: 3 additions & 0 deletions includes/cf7a-antispam-b8.php → core/CF7_AntiSpam_B8.php
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

namespace CF7_AntiSpam\Core;

/**
* B8 related functions
*
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
<?php

namespace CF7_AntiSpam\Core;

/**
* Fired during deactivation.
*
Expand Down
Loading

0 comments on commit def47ed

Please sign in to comment.