-
Notifications
You must be signed in to change notification settings - Fork 3
/
wordpress-popular-posts-feed.php
78 lines (68 loc) · 1.86 KB
/
wordpress-popular-posts-feed.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
<?php
/**
* The plugin bootstrap file.
*
* @link https://cabrerahector.com/
* @since 1.0.0
* @package WordPressPopularPosts\Feed
*
* @wordpress-plugin
* Plugin Name: Popular Posts Feed
* Plugin URI: https://cabrerahector.com/
* Description: Adds a popular posts feed to your site.
* Version: 2.0.0
* Requires at least: 5.3
* Requires PHP: 5.3
* Author: Hector Cabrera
* Author URI: https://cabrerahector.com/
* License: GPL-3.0+
* License URI: http://www.gnu.org/licenses/gpl-3.0.txt
*/
namespace WordPressPopularPosts\Feed;
// File is being accessed directly, abort.
if ( ! defined( 'WPINC' ) ) {
die;
}
/**
* Initializes the plugin.
*
* @since 1.0.0
*/
function init() {
if ( class_exists('WordPressPopularPosts\WordPressPopularPosts', false) ) {
add_action( 'init', __NAMESPACE__ . '\register_feed' );
}
else {
add_action( 'admin_notices', __NAMESPACE__ . '\admin_notice' );
}
}
/**
* Registers the popular feed.
*
* @since 1.0.0
*/
function register_feed() {
add_feed( 'popular-posts', __NAMESPACE__ . '\generate_feed' );
}
/**
* Generates the feed.
*
* @since 1.0.0
*/
function generate_feed() {
add_filter( 'pre_option_rss_use_excerpt', '__return_zero' );
require plugin_dir_path( __FILE__ ) . 'feed.php';
}
/**
* Generates an admin notice warning the user that
* WordPress Popular Posts must be active in order
* to use the plugin.
*
* @since 1.0.0
*/
function admin_notice() {
$class = 'notice notice-error';
$message = __( 'Popular Posts Feed requires WordPress Popular Posts in order to work.', 'wordpress-popular-posts-feed' );
printf( '<div class="%1$s"><p>%2$s</p></div>', esc_attr( $class ), esc_html( $message ) );
}
add_action( 'plugins_loaded', __NAMESPACE__ . '\init' );