forked from abhijitrakas/post-contributor
-
Notifications
You must be signed in to change notification settings - Fork 0
/
post-contributor.php
88 lines (78 loc) · 2.66 KB
/
post-contributor.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
79
80
81
82
83
84
85
86
87
88
<?php
defined( 'ABSPATH' ) or die( 'No script kiddies please!' );
/*
Plugin Name: Post Contributor
Plugin URI: http://coffeecupweb.com/post-contributors
Description: Very handy plugin to show author contribution in particular post
Version: 1.1.6
Author: Abhijit Rakas
Author URI: http://coffeecupweb.com/post-contributors
License: GPL2
Post Contributor is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 2 of the License, or
any later version.
Post Contributor is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with Post Contributor. If not, see http://www.gnu.org/licenses/gpl-2.0.html.
*/
define( 'POST_CONTRIBUTOR_ASSETS', plugins_url( '/', __FILE__ ) . 'built_assets/' );
class ExecutableClass
{
public function __construct()
{
add_shortcode('post-authors',[$this,'add_post_authors']);
add_shortcode('contributor',[$this,'show_post_authors']);
spl_autoload_register([$this,'requiredClassLoader']);
if( is_admin() )
{
new PostClass();
new FetchClass();
new OptionClass();
}
}
public function add_post_authors($atts)
{
$atts = shortcode_atts( array(
'class' => '',
'id' => '',
), $atts );
$userposts = get_post_meta(get_the_ID(),'contributedUsers');
$userposts = explode(',',$userposts[0]['postauthors']);
printf('<ul id="%s">',$atts['id']);
foreach($userposts as $userpost){
$userdata = get_userdata($userpost);
printf('<li class="%s">%s</li>',$atts['class'],$userdata->display_name);
}
echo '</ul>';
}
public function show_post_authors($atts)
{
$atts = shortcode_atts( array(
'class' => '',
'id' => '',
), $atts );
$userposts = get_post_meta(get_the_ID(),'contributedUsers');
$userposts = explode(',',$userposts[0]['postauthors']);
printf('<div id=%s>',$atts['id']);
foreach($userposts as $userpost){
$userdata = get_userdata($userpost);
printf('<div class="%s">%s</div>',$atts['class'],$userdata->display_name);
}
echo '</div>';
}
/*
* Load all classes
*
*/
public function requiredClassLoader($class)
{
if ( is_readable( plugin_dir_path( dirname( __FILE__ ) ) . 'post-contributor/classes/' . $class . '.php' ) ){
require_once( plugin_dir_path( dirname( __FILE__ ) ) . 'post-contributor/classes/' . $class . '.php' );
}
}
}
new ExecutableClass();