Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/plugin autoload #60

Merged
merged 2 commits into from
Oct 8, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions wp-content/plugins/ewplugin/admin/class-plugin-admin.php
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace EwStarter;
namespace EwStarter\Admin;

/**
* The admin-specific functionality of the plugin.
Expand All @@ -21,7 +21,7 @@ class Plugin_Admin {
* @access private
* @var string $plugin_name The ID of this plugin.
*/
private $plugin_name;
private string $plugin_name;

/**
* The version of this plugin.
Expand All @@ -30,7 +30,7 @@ class Plugin_Admin {
* @access private
* @var string $version The current version of this plugin.
*/
private $version;
private string $version;

/**
* Initialize the class and set its properties.
Expand All @@ -49,15 +49,15 @@ public function __construct( string $plugin_name, string $version ) {
*
* @since 1.0.0
*/
public function enqueue_styles() {
public function enqueue_styles(): void {
}

/**
* Register the JavaScript for the admin area.
*
* @since 1.0.0
*/
public function enqueue_scripts() {
public function enqueue_scripts(): void {
}

}
3 changes: 3 additions & 0 deletions wp-content/plugins/ewplugin/constants.php
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,9 @@
// Plugin url
define( 'PLUGIN_URL', plugin_dir_url( __FILE__ ) );

// Plugin namespace
define( 'PLUGIN_NAMESPACE', 'EwStarter' );

// Plugin textdomain
define( 'PLUGIN_TEXTDOMAIN', 'enterwell-plugin' );

Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace EwStarter;
namespace EwStarter\Controllers;

use Ew\WpHelpers\Controllers\AController;

Expand All @@ -9,8 +9,8 @@
* @package EWPlugin
*/
abstract class APlugin_Controller extends AController {
protected $base_route = 'wp-ew';
protected $version = 'v1';
protected string $base_route = 'wp-ew';
protected string $version = 'v1';

/**
* Gets controller base route.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@
* Time: 14:48
*/

namespace EwStarter;
namespace EwStarter\Controllers;

use Exception;
use WP_REST_Request;
use WP_REST_Response;
use EwStarter\Exceptions\Validation_Exception;
use EwStarter\Services\User_Applications_Service;

/**
* Class User_Applications_Controller
Expand All @@ -16,11 +22,11 @@ class User_Applications_Controller extends APlugin_Controller {
/**
* @var User_Applications_Service
*/
private $user_applications_service;
private User_Applications_Service $user_applications_service;

/**
* User_Applications_Controller constructor.
* @throws \Exception
* @throws Exception
*/
public function __construct() {
parent::__construct( 'user-applications' );
Expand Down Expand Up @@ -49,19 +55,19 @@ public function register_routes() {
/**
* Creates user application
*
* @param \WP_REST_Request $request
* @param WP_REST_Request $request
*
* @return \WP_REST_Response
* @return WP_REST_Response
*/
public function create_user_application( \WP_REST_Request $request ): \WP_REST_Response {
public function create_user_application( WP_REST_Request $request ): WP_REST_Response {
try {
// Create user application from params
$user_application = $this->user_applications_service->create_user_application( $request->get_params() );

return $this->ok( $user_application );
} catch ( Validation_Exception $e ) {
return $this->bad_request( $e->getMessage() );
} catch ( \Exception $e ) {
} catch ( Exception $e ) {
return $this->exception_response( $e );
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Time: 12:12
*/

namespace EwStarter;
namespace EwStarter\Exceptions;

/**
* Base template class for validation exception.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Time: 14:55
*/

namespace EwStarter;
namespace EwStarter\Helpers;

/**
* Class Random_Values_Helper
Expand Down
121 changes: 0 additions & 121 deletions wp-content/plugins/ewplugin/includes/class-plugin-loader.php

This file was deleted.

17 changes: 17 additions & 0 deletions wp-content/plugins/ewplugin/load-plugin.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

namespace EwStarter;

use EwStarter\Main\Plugin_Activator;
use EwStarter\Main\Plugin_Deactivator;
use EwStarter\Main\Plugin;

require_once plugin_dir_path( __FILE__ ) . 'constants.php';
require_once plugin_dir_path( __FILE__ ) . 'plugin-autoload-register.php';

// Register activation/deactivation hooks
register_activation_hook( __FILE__, [ Plugin_Activator::class, 'activate' ] );
register_deactivation_hook( __FILE__, [ Plugin_Deactivator::class, 'deactivate' ] );

$plugin = new Plugin();
$plugin->run();
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace EwStarter;
namespace EwStarter\Main;

/**
* Fired during plugin activation.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace EwStarter;
namespace EwStarter\Main;

/**
* Fired during plugin deactivation.
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<?php

namespace EwStarter;
namespace EwStarter\Main;

/**
* Define the internationalization functionality.
Expand All @@ -20,16 +20,16 @@ class Plugin_i18n {
*
* @since 1.0.0
* @access private
* @var string $domain The domain identifier for this plugin.
* @var string $domain The domain identifier for this plugin.
*/
private $domain;
private string $domain;

/**
* Load the plugin text domain for translation.
*
* @since 1.0.0
*/
public function load_plugin_textdomain() {
public function load_plugin_textdomain(): void {

load_plugin_textdomain(
$this->domain,
Expand All @@ -42,10 +42,11 @@ public function load_plugin_textdomain() {
/**
* Set the domain equal to that of the specified domain.
*
* @param string $domain The domain that represents the locale of this plugin.
*
* @since 1.0.0
* @param string $domain The domain that represents the locale of this plugin.
*/
public function set_domain( $domain ) {
public function set_domain( string $domain ): void {
$this->domain = $domain;
}

Expand Down
Loading
Loading