Skip to content

Commit

Permalink
First rewrite
Browse files Browse the repository at this point in the history
  • Loading branch information
ajaydsouza committed Jul 9, 2023
1 parent 8366a1d commit 821059f
Show file tree
Hide file tree
Showing 32 changed files with 1,164 additions and 821 deletions.
18 changes: 11 additions & 7 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -12,17 +12,21 @@ Display a list of the popular authors. A Top 10 WordPress plugin addon.

## Description

[Popular Authors WordPress plugin](https://webberzone.com/downloads/popular-authors/) is an addon for [Top 10](https://webberzone.com/plugins/top-10/) that allows you display the top authors on your blog by page views.
[Popular Authors WordPress plugin](https://webberzone.com/downloads/popular-authors/) is the ultimate addon for [Top 10](https://webberzone.com/plugins/top-10/), the best plugin to showcase your most popular posts on WordPress. With Popular Authors, you can also highlight the top authors on your blog by page views and give them the recognition they deserve.

The most popular authors can be displayed using either the block, shortcode or via the inbuilt widget. You can also use the function `wzpa_list_popular_authors()` to display popular authors programmatically.
Popular Authors lets you display the most popular authors using different methods. You can use the Gutenberg block, the shortcode, the widget or the template tag to insert the popular authors list anywhere on your site. You can also customize the appearance and settings of each method to suit your needs.

Popular Authors also gives you the flexibility to choose the time range for calculating the page views. You can show the popular authors of all time, or limit it to a specific period, such as last day, last week, last month, etc. This way, you can keep your popular authors list fresh and dynamic.

Popular Authors is a must-have addon for Top 10 if you want to boost your blog's engagement and credibility. By showcasing your most popular authors, you can attract more readers, increase social shares, and build a loyal community around your blog.

### Features

* Block: Add a Gutenberg block by searching for `popular authors` or `author`
* Multi-widget capable: You can have several widgets of Popular Authors each with its own settings
* Custom Time Range: List popular authors within a specific time range (eg. last 1 day, last 7 days, last 30 days, etc.)
* Shortcode: Use the `[wzpa_popular_authors]` shortcode to display your most popular authors
* Template tags: Use `wzpa_list_popular_authors()` to display the popular authors programmatically
* Block: Add a Gutenberg block by searching for `popular authors` or `author` and customize its settings and style
* Multi-widget capable: You can have multiple widgets of Popular Authors on your sidebar or footer, each with its own title, number of authors, time range, and more
* Custom Time Range: List popular authors within a specific time range (eg. last 1 day, last 7 days, last 30 days, etc.) or show the all-time favorites
* Shortcode: Use the `[wzpa_popular_authors]` shortcode to display your most popular authors anywhere in your posts or pages
* Template tags: Use `wzpa_list_popular_authors()` to display the popular authors programmatically in your theme files or plugins

## Screenshots

Expand Down
24 changes: 20 additions & 4 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "webberzone/popular-authors",
"description": "Show a list of the popular authors using the widget or shortcode. A Top 10 WordPress plugin addon",
"description": "Showcase the popular authors on your site. A Top 10 WordPress plugin addon",
"type": "wordpress-plugin",
"keywords": [
"popular authors",
Expand All @@ -9,15 +9,31 @@
"popular",
"authors"
],
"license": "gpl-2.0-or-later",
"license": "GPL-2.0-or-later",
"authors": [
{
"name": "WebberZone",
"email": "[email protected]",
"role": "Developer"
}
],
"requires": {
"php": ">=7"
"php": ">=7.1"
},
"require-dev": {
"szepeviktor/phpstan-wordpress": "^1.3",
"phpstan/extension-installer": "^1.3",
"phpstan/phpstan": "^1.10",
"php-stubs/wordpress-stubs": "^6.2",
"wp-coding-standards/wpcs": "^2.3",
"dealerdirect/phpcodesniffer-composer-installer": "^0.7",
"phpcompatibility/phpcompatibility-wp": "^2.1",
"yoast/phpunit-polyfills": "^1.0",
"phpunit/phpunit": "^5.7.21 || ^6.5 || ^7.5"
},
"config": {
"allow-plugins": {
"phpstan/extension-installer": true,
"dealerdirect/phpcodesniffer-composer-installer": true
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@
* @package Popular_Authors\Admin
*/

// If this file is called directly, abort.
namespace WebberZone\Popular_Authors\Admin;

if ( ! defined( 'WPINC' ) ) {
die;
}
Expand All @@ -15,7 +16,7 @@
*
* @since 1.1.0
*/
class WZPA_Admin {
class Admin {

/**
* Constructor class.
Expand All @@ -24,8 +25,8 @@ class WZPA_Admin {
*/
public function __construct() {
add_filter( 'admin_notices', array( $this, 'admin_notices' ) );
add_filter( 'tptn_settings_sections', array( $this, 'add_settings_section' ) );
add_filter( 'tptn_registered_settings', array( $this, 'settings_popular_authors' ) );
add_filter( 'tptn_settings_sections', array( $this, 'add_settings_section' ), 11 );
add_filter( 'tptn_registered_settings', array( $this, 'settings_popular_authors' ), 11 );
}

/**
Expand Down Expand Up @@ -80,8 +81,8 @@ public static function settings_popular_authors( $settings ) {

$new_settings = array(
'popular-authors' => array(
'wzpa_cache' => array(
'id' => 'wzpa_cache',
'cache' => array(
'id' => 'cache',
'name' => esc_html__( 'Cache output', 'top-10' ),
'desc' => esc_html__( 'Turn this ON to cache the HTML output. This option uses the same settings as Top 10 and creates similar cache keys.', 'top-10' ),
'type' => 'checkbox',
Expand Down Expand Up @@ -188,7 +189,4 @@ public static function settings_popular_authors( $settings ) {

return array_merge( $settings, $new_settings );
}

}

new WZPA_Admin();
47 changes: 47 additions & 0 deletions includes/autoloader.php
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' );
1 change: 0 additions & 1 deletion includes/blocks/index.php

This file was deleted.

72 changes: 0 additions & 72 deletions includes/blocks/register-blocks.php

This file was deleted.

122 changes: 122 additions & 0 deletions includes/class-main.php
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' );
}
}
Loading

0 comments on commit 821059f

Please sign in to comment.