-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #15 from WebberZone/oop
Implemented OOP
- Loading branch information
Showing
33 changed files
with
1,174 additions
and
823 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,47 @@ | ||
<?php | ||
/** | ||
* Autoloads classes from the WebberZone\Popular_Authors namespace. | ||
* | ||
* @package WebberZone\Popular_Authors | ||
*/ | ||
|
||
namespace WebberZone\Popular_Authors; | ||
|
||
defined( 'ABSPATH' ) || exit; | ||
|
||
/** | ||
* Autoloader for WebberZone\Popular_Authors classes. | ||
* | ||
* @param string $class_name The name of the class to load. | ||
*/ | ||
function autoload( $class_name ) { | ||
$namespace = __NAMESPACE__; | ||
$classes_subfolder = 'includes'; | ||
|
||
if ( false !== strpos( $class_name, $namespace ) ) { | ||
$classes_dir = realpath( POP_AUTHOR_PLUGIN_DIR ) . DIRECTORY_SEPARATOR . $classes_subfolder . DIRECTORY_SEPARATOR; | ||
|
||
// Project namespace. | ||
$project_namespace = $namespace . '\\'; | ||
$length = strlen( $project_namespace ); | ||
|
||
$class_file = substr( $class_name, $length ); // Remove top level namespace (that is the current dir). | ||
$class_file = str_replace( '_', '-', strtolower( $class_file ) ); // Swap underscores for dashes and lowercase. | ||
|
||
// Prepend `class-` to the filename (last class part). | ||
$class_parts = explode( '\\', $class_file ); // Split the class name into parts. | ||
$last_index = count( $class_parts ) - 1; // Get the last index. | ||
$class_parts[ $last_index ] = 'class-' . $class_parts[ $last_index ]; // Replace the last part with `class-`. | ||
|
||
// Join everything back together and add the file extension. | ||
$class_file = implode( DIRECTORY_SEPARATOR, $class_parts ) . '.php'; | ||
$location = $classes_dir . $class_file; | ||
|
||
if ( ! is_file( $location ) ) { | ||
return; | ||
} | ||
|
||
require_once $location; | ||
} | ||
} | ||
spl_autoload_register( __NAMESPACE__ . '\autoload' ); |
This file was deleted.
Oops, something went wrong.
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,122 @@ | ||
<?php | ||
/** | ||
* Main plugin class. | ||
* | ||
* @package WebberZone\Popular_Authors | ||
*/ | ||
|
||
namespace WebberZone\Popular_Authors; | ||
|
||
if ( ! defined( 'WPINC' ) ) { | ||
exit; | ||
} | ||
|
||
/** | ||
* Main plugin class. | ||
* | ||
* @since 1.2.0 | ||
*/ | ||
final class Main { | ||
/** | ||
* The single instance of the class. | ||
* | ||
* @var Main | ||
*/ | ||
private static $instance; | ||
|
||
/** | ||
* Admin. | ||
* | ||
* @since 1.2.0 | ||
* | ||
* @var object Admin. | ||
*/ | ||
public $admin; | ||
|
||
/** | ||
* Shortcodes. | ||
* | ||
* @since 1.2.0 | ||
* | ||
* @var object Shortcodes. | ||
*/ | ||
public $shortcodes; | ||
|
||
/** | ||
* Blocks. | ||
* | ||
* @since 1.2.0 | ||
* | ||
* @var object Blocks. | ||
*/ | ||
public $blocks; | ||
|
||
/** | ||
* Gets the instance of the class. | ||
* | ||
* @since 1.2.0 | ||
* | ||
* @return Main | ||
*/ | ||
public static function get_instance() { | ||
if ( null === self::$instance ) { | ||
self::$instance = new self(); | ||
self::$instance->init(); | ||
} | ||
|
||
return self::$instance; | ||
} | ||
|
||
/** | ||
* A dummy constructor. | ||
* | ||
* @since 1.2.0 | ||
*/ | ||
private function __construct() { | ||
// Do nothing. | ||
} | ||
|
||
/** | ||
* Initializes the plugin. | ||
* | ||
* @since 1.2.0 | ||
*/ | ||
private function init() { | ||
$this->shortcodes = new Frontend\Shortcodes(); | ||
$this->blocks = new Frontend\Blocks\Blocks(); | ||
|
||
$this->hooks(); | ||
|
||
if ( is_admin() ) { | ||
$this->admin = new Admin\Admin(); | ||
} | ||
} | ||
|
||
/** | ||
* Run the hooks. | ||
* | ||
* @since 1.2.0 | ||
*/ | ||
public function hooks() { | ||
add_action( 'init', array( $this, 'initiate_plugin' ) ); | ||
add_action( 'widgets_init', array( $this, 'register_widgets' ) ); | ||
} | ||
|
||
/** | ||
* Initialise the plugin translations and media. | ||
* | ||
* @since 1.2.0 | ||
*/ | ||
public function initiate_plugin() { | ||
load_plugin_textdomain( 'popular-authors', false, dirname( plugin_basename( POP_AUTHOR_PLUGIN_FILE ) ) . '/languages/' ); | ||
} | ||
|
||
/** | ||
* Initialise the Top 10 widgets. | ||
* | ||
* @since 1.2.0 | ||
*/ | ||
public function register_widgets() { | ||
register_widget( '\WebberZone\Popular_Authors\Frontend\Widgets\Authors_Widget' ); | ||
} | ||
} |
Oops, something went wrong.