forked from pressoholics/prso-gravity-forms-adv-uploader
/
class.prso-gravity-forms-adv-uploader.php
191 lines (149 loc) · 4.95 KB
/
class.prso-gravity-forms-adv-uploader.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
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
<?php
class PrsoGformsAdvUploader {
protected static $class_config = array();
protected $current_screen = NULL;
protected $plugin_ajax_nonce = 'prso_gforms_adv_uploader-ajax-nonce';
protected $plugin_path = PRSOGFORMSADVUPLOADER__PLUGIN_DIR;
protected $plugin_url = PRSOGFORMSADVUPLOADER__PLUGIN_URL;
protected $plugin_textdomain = PRSOGFORMSADVUPLOADER__DOMAIN;
function __construct( $config = array() ) {
//Cache plugin congif options
self::$class_config = $config;
//Set textdomain
add_action( 'after_setup_theme', array($this, 'plugin_textdomain') );
//Init plugin
add_action( 'init', array($this, 'init_plugin'), 999 );
add_action('init', array($this, 'removeDemoModeLink') );
add_action( 'admin_menu', array($this, 'remove_redux_menu'),12 );
//Init plugin core
$core_include = $this->plugin_path . 'class.core.init-uploader.php';
include_once( $core_include );
$PluginInit = new PrsoGformsAdvUploaderInit();
}
function removeDemoModeLink() { // Be sure to rename this function to something more unique
if ( class_exists('ReduxFrameworkPlugin') ) {
remove_filter( 'plugin_row_meta', array( ReduxFrameworkPlugin::get_instance(), 'plugin_metalinks'), null, 2 );
}
if ( class_exists('ReduxFrameworkPlugin') ) {
remove_action('admin_notices', array( ReduxFrameworkPlugin::get_instance(), 'admin_notices' ) );
}
}
function remove_redux_menu() {
remove_submenu_page('tools.php','redux-about');
}
/**
* Attached to activate_{ plugin_basename( __FILES__ ) } by register_activation_hook()
* @static
*/
public static function plugin_activation( $network_wide ) {
}
/**
* Attached to deactivate_{ plugin_basename( __FILES__ ) } by register_deactivation_hook()
* @static
*/
public static function plugin_deactivation( ) {
}
/**
* Setup plugin textdomain folder
* @public
*/
public function plugin_textdomain() {
load_plugin_textdomain( $this->plugin_textdomain, FALSE, $this->plugin_path . '/languages/' );
}
/**
* init_plugin
*
* Used By Action: 'init'
*
*
* @access public
* @author Ben Moody
*/
public function init_plugin() {
//Init vars
$options = self::$class_config;
$PluginInit = NULL;
if( is_admin() ) {
//PLUGIN OPTIONS FRAMEWORK -- comment out if you dont need options
$this->load_redux_options_framework();
}
//Add shortcodes
add_shortcode('get_adv_uploads', array($this, 'adv_post_attachments_shortcode'));
}
/**
* load_redux_options_framework
*
* Loads Redux options framework as well as the unique config file for this plugin
*
* NOTE!!!!
* You WILL need to make sure some unique constants as well as the class
* name in the plugin config file 'inc/ReduxConfig/ReduxConfig.php'
*
* @access public
* @author Ben Moody
*/
protected function load_redux_options_framework() {
//Init vars
$framework_inc = $this->plugin_path . 'inc/ReduxFramework/ReduxCore/framework.php';
$framework_config = $this->plugin_path . 'inc/ReduxConfig/ReduxConfig.php';
//Try and load redux framework
if ( !class_exists('ReduxFramework') && file_exists($framework_inc) ) {
require_once( $framework_inc );
}
//Try and load redux config for this plugin
if ( file_exists($framework_config) ) {
require_once( $framework_config );
}
}
/**
* adv_post_attachments_shortcode
*
* Shortcode 'get_adv_uploads'
*
* Builds a simple html ul list of all files attached to the post being displayed
*
* Filters:
* 'prso_gform_pluploader_shortcode_attach_title' - filter individual attachment title
* 'prso_gform_pluploader_shortcode' - Filter shortcode output
*
* @access public
* @author Ben Moody
*/
public function adv_post_attachments_shortcode( $attr ) {
//Init vars
global $post;
$attachments = NULL;
$output = NULL;
extract(shortcode_atts(array(
'order' => 'ASC',
'orderby' => 'menu_order ID',
'id' => $post ? $post->ID : 0,
'exclude' => '',
'target' => '_blank'
), $attr, 'get_adv_uploads'));
$attachments = get_children(
array(
'post_parent' => $id,
'exclude' => $exclude,
'post_status' => 'inherit',
'post_type' => 'attachment',
'order' => $order,
'orderby' => $orderby
)
);
//Loop attachments and build html list
if( !empty($attachments) ) {
$output = '<ul class="gforms-adv-uploader-attachments">';
foreach( $attachments as $attachment_id => $Attachment ) {
$attachment_title = apply_filters( 'prso_gform_pluploader_shortcode_attach_title', $Attachment->post_title . ' ('. $Attachment->post_mime_type .')', $Attachment );
$output.= '<li>';
$output.= '<a href="'. $Attachment->guid .'" target="'. $target .'">';
$output.= $attachment_title;
$output.= '</a>';
$output.= '</li>';
}
$output.= '</ul>';
}
return apply_filters( 'prso_gform_pluploader_shortcode', $output, $attachments );
}
}