PluginProbe
Arconix Shortcodes / trunk
Arconix Shortcodes vtrunk
2.2.1 trunk 1.0.3 1.0.4 1.1.0 1.1.1 1.1.2 1.2.0 2.0.0 2.0.1 2.0.2 2.0.3 2.0.4 2.1.1 2.1.10 2.1.11 2.1.12 2.1.13 2.1.14 2.1.15 2.1.16 2.1.17 2.1.18 2.1.19 2.1.2 All 34 releases
arconix-shortcodes / plugin.php

plugin.php in Arconix Shortcodes trunk, at plugin.php

369 lines 15.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2 /**
3 * Plugin Name: Arconix Shortcodes
4 * Plugin URI: https://www.tychesoftwares.com/
5 * Description: A handy collection of shortcodes for your site.
6 *
7 * Version: 2.2.1
8 *
9 * Author: Tyche Softwares
10 * Author URI: https://www.tychesoftwares.com/
11 *
12 * Text Domain: acs
13 *
14 * License: GNU General Public License v2.0
15 * License URI: http://www.opensource.org/licenses/gpl-license.php
16 */
17
18 require_once( plugin_dir_path(__FILE__) . 'includes/shortcodes.php' );
19
20
21 class Arconix_Shortcodes {
22
23 /**
24 * Stores the current version of the plugin.
25 *
26 * @since 2.0.4
27 * @access private
28 * @var string $version Current plugin version.
29 */
30 const VERSION = '2.2.1';
31
32 /**
33 * The url path to this plugin.
34 *
35 * @since 1.0.0
36 * @access private
37 * @var string $url The url path to this plugin
38 */
39 protected $url;
40
41 /**
42 * Construct Method
43 *
44 * @since 1.0.0
45 * @version 1.2.0
46 */
47 public function __construct() {
48 $this->url = trailingslashit( plugin_dir_url( __FILE__ ) );
49
50 $this->constants();
51
52 add_action( 'init', 'acs_register_shortcodes' );
53 add_action( 'add_meta_boxes', array( $this, 'metabox' ) );
54 add_action( 'wp_enqueue_scripts', array( $this, 'scripts' ) );
55 add_action( 'admin_enqueue_scripts', array( $this, 'admin_css' ) );
56 /**
57 * We have commented this, because we will create a feed from our site and then we can enable this widget.
58 */
59 //add_action( 'wp_dashboard_setup', array( $this, 'dashboard_widget' ) );
60
61 add_filter( 'widget_text', 'do_shortcode' );
62
63 $is_admin = is_admin();
64
65 if ( true === $is_admin ) {
66 add_action( 'init', array ($this , 'shortcodes_load_files') );
67 add_filter( 'ts_deativate_plugin_questions', array( $this, 'shortcodes_deactivate_add_questions' ), 10, 1 );
68 add_filter( 'ts_tracker_data', array( $this, 'shortcodes_ts_add_plugin_tracking_data' ), 10, 1 );
69 add_filter( 'ts_tracker_opt_out_data', array( $this, 'shortcodes_get_data_for_opt_out' ), 10, 1 );
70 add_action( 'admin_init', array( $this, 'shortcodes_admin_actions' ) );
71 }
72 }
73
74 function shortcodes_load_files () {
75 require_once( plugin_dir_path(__FILE__) . 'includes/arconix-shortcodes-all-component.php' );
76 }
77
78 /**
79 * Define plugin constants
80 *
81 * @since 1.1.0
82 */
83 function constants() {
84 define( 'ACS_VERSION', self::VERSION ); // kept for backwards compatibility in case anyone else is checking or using it
85
86 /*
87 define( 'ACS_URL', trailingslashit( plugin_dir_url( __FILE__ ) ) );
88 define( 'ACS_INCLUDES_URL', trailingslashit( ACS_URL . 'includes' ) );
89 define( 'ACS_CSS_URL', trailingslashit( ACS_INCLUDES_URL . 'css' ) );
90 define( 'ACS_IMAGES_URL', trailingslashit( ACS_URL . 'images' ) );
91 define( 'ACS_ADMIN_IMAGES_URL', trailingslashit( ACS_IMAGES_URL . 'admin' ) );
92 define( 'ACS_DIR', trailingslashit( plugin_dir_path( __FILE__ ) ) );
93 define( 'ACS_INCLUDES_DIR', trailingslashit( ACS_DIR . 'includes' ) );
94 */
95 }
96
97 /**
98 * Register the necessary Javascript and CSS, which can be overridden in 3 different ways.
99 * If you'd like to use a different version of the jQuery Tools script {@link http://jquerytools.org/download/}
100 * you can add a filter that overrides the the url, version and dependency.
101 *
102 * If you would like to bundle the Javacsript or CSS funtionality into another file and prevent either of the plugin files
103 * from loading at all, return false to the desired pre_register filters
104 *
105 * @example add_filter( 'pre_register_arconix_shortcodes_js', '__return_false' );
106 *
107 * If you'd like to modify the Javascript or CSS that is used by the shortcodes, you can copy the arconix-shortcodes.js
108 * or arconix-shortcodes.css files to the root of your theme's folder. That will be loaded in place of the plugin's
109 * version, which means you can modify it to your heart's content and know the file will be safe when the plugin
110 * is updated in the future.
111 *
112 * @link Codex reference: apply_filters()
113 * @link Codex reference: wp_register_script()
114 * @link Codex reference: get_stylesheet_directory()
115 * @link Codex reference: get_stylesheet_directory_uri()
116 * @link Codex reference: get_template_directory()
117 * @link Codex reference: get_template_directory_uri()
118 * @link Codex reference: wp_enqueue_style()
119 *
120 * @since 0.9
121 * @version 2.0.2
122 */
123 function scripts() {
124 // Provide script registration args so they can be filtered if necessary
125 $jqt_args = apply_filters( 'arconix_jquerytools_reg', array(
126 'url' => $this->url . "includes/jquery.tools.min.js",
127 'ver' => '1.2.7',
128 'dep' => 'jquery'
129 ) );
130
131 wp_register_script( 'jquery-tools', esc_url( $jqt_args['url'] ), array( $jqt_args['dep'] ), $jqt_args['ver'], true );
132
133
134 // Set the FontAwesome CSS version to load. Can be overridden via filter
135 $fa_version = apply_filters( 'arconix_fontawesome_version', '4.6.3' );
136
137 /*
138 * Allow users to override the FontAwesome CSS registration params. This is not
139 * the recommended way of changing the version of the CSS to be loaded. To do
140 * that, filter $fa_version above
141 */
142 $fa_args = apply_filters( 'arconix_fontawesome_css', array(
143 'url' => $this->url . "includes/css/font-awesome.min.css",
144 'ver' => '4.6.3',
145 ));
146
147 wp_enqueue_style( 'font-awesome', $fa_args['url'], false, $fa_args['ver'] );
148
149 // Use the .min files if SCRIPT_DEBUG is turned off.
150 $suffix = ( defined( 'SCRIPT_DEBUG' ) && SCRIPT_DEBUG ) ? '' : '.min';
151
152 // Register the javascript - Check the child theme directory first, the parent theme second, otherwise load the plugin version
153 if( apply_filters( 'pre_register_arconix_shortcodes_js', true ) ) {
154 if( file_exists( get_stylesheet_directory() . '/arconix-shortcodes.js' ) )
155 wp_register_script( 'arconix-shortcodes-js', get_stylesheet_directory_uri() . '/arconix-shortcodes.js', array( 'jquery-tools' ), self::VERSION, true );
156 elseif( file_exists( get_template_directory() . '/arconix-shortcodes.js' ) )
157 wp_register_script( 'arconix-shortcodes-js', get_template_directory_uri() . '/arconix-shortcodes.js', array( 'jquery-tools' ), self::VERSION, true );
158 else
159 wp_register_script( 'arconix-shortcodes-js', $this->url . "includes/arconix-shortcodes{$suffix}.js", array( 'jquery-tools' ), self::VERSION, true );
160 }
161
162 // Load the CSS - Check the child theme directory first, the parent theme second, otherwise load the plugin version
163 if( apply_filters( 'pre_register_arconix_shortcodes_css', true ) ) {
164 if( file_exists( get_stylesheet_directory() . '/arconix-shortcodes.css' ) )
165 wp_enqueue_style( 'arconix-shortcodes', get_stylesheet_directory_uri() . '/arconix-shortcodes.css', false, self::VERSION );
166 elseif( file_exists( get_template_directory() . '/arconix-shortcodes.css' ) )
167 wp_enqueue_style( 'arconix-shortcodes', get_template_directory_uri() . '/arconix-shortcodes.css', false, self::VERSION );
168 else
169 wp_enqueue_style( 'arconix-shortcodes', $this->url . "includes/css/arconix-shortcodes{$suffix}.css", false, self::VERSION );
170 }
171
172 }
173
174 /**
175 * Adds a meta box to the sidebar column on the Post and Page edit screens.
176 *
177 * The list of available post_types is filterable for themes and plugins
178 *
179 * @link Codex reference: apply_filters()
180 * @link Codex reference: add_meta_box()
181 *
182 * @since 1.1.0
183 */
184 function metabox() {
185 // Allow a theme or plugin to filter the list of post types this meta box is added to
186 $post_types = apply_filters( 'arconix_shortcodes_meta_box_post_types', array( 'post', 'page' ) );
187
188 foreach( (array) $post_types as $post_type ) {
189 add_meta_box( 'ac-shortcode-list', __( 'Arconix Shortcode List', 'acs' ), array( $this, 'shortcodes_box' ), $post_type, 'side' );
190 }
191 }
192
193 /**
194 * Callback to display the meta box content
195 *
196 * @uses get_arconix_shortcode_list() Defined in /includes/shortcodes.php
197 *
198 * @see ACS_ADMIN_IMAGES_URL Defined in this file
199 *
200 * @since 1.1.0
201 */
202 function shortcodes_box() {
203 $shortcodes = get_arconix_shortcode_list();
204
205 if( ! $shortcodes or ! is_array( $shortcodes ) )
206 return;
207
208 $return = '<p><a href="https://www.tychesoftwares.com/docs/docs/shortcodes/shortcode-reference/"><img src="' . $this->url . 'images/admin/page-16x16.png">Documentation</a></p><ul>';
209 foreach( (array) $shortcodes as $shortcode ) {
210 $return .= '<li>[' . $shortcode . ']</li>';
211 }
212 $return .= '</ul>';
213
214 echo $return;
215 }
216
217 /**
218 * Adds a news widget to the dashboard.
219 *
220 * If the filter is returned false or the logged in user isn't an Admin user, it will prevent the dashboard widget
221 * from loading. It's a little cleaner than other solutions available.
222 *
223 * @example add_filter( 'pre_register_arconix_shortcodes_dashboard_widget', '__return_false' );
224 *
225 * @link Codex reference: wp_add_dashboard_widget()
226 * @link Codex reference: current_user_can()
227 *
228 * @since 1.0
229 * @version 1.2.0
230 */
231 function dashboard_widget() {
232 if( apply_filters( 'pre_register_arconix_shortcodes_dashboard_widget', true ) and
233 apply_filters( 'arconix_shortcodes_dashboard_widget_security', current_user_can( 'manage_options' ) ) )
234 wp_add_dashboard_widget( 'ac-shortcodes', 'Arconix Shortcodes', array( $this, 'acs_dash_widget' ) );
235 }
236
237 /**
238 * Output for the dashboard widget
239 *
240 * @link Codex reference: wp_widget_rss_output()
241 *
242 * @since 1.0
243 * @version 1.1.0
244 */
245 public function acs_dash_widget() {
246 echo '<div class="rss-widget">';
247
248 wp_widget_rss_output( array(
249 'url' => 'http://arconixpc.com/tag/arconix-shortcodes/feed', // feed url
250 'title' => 'Arconix Shortcodes News', // feed title
251 'items' => 3, //how many posts to show
252 'show_summary' => 1, // 1 = display excerpt
253 'show_author' => 0, // 1 = display author
254 'show_date' => 1 // 1 = display post date
255 ) );
256 ?>
257 <div class="acs-widget-bottom">
258 <ul>
259 <li><a href="http://arcnx.co/aswiki"><img src="<?php echo $this->url . 'images/admin/page-16x16.png'; ?>">Documentation</a></li>
260 <li><a href="http://arcnx.co/ashelp"><img src="<?php echo $this->url . 'images/admin/help-16x16.png'; ?>">Support Forum</a></li>
261 <li><a href="http://arcnx.co/assource"><img src="<?php echo $this->url . 'images/admin/github-16x16.png'; ?>">Source Code</a></li>
262 </ul>
263 </div></div>
264 <?php
265 }
266
267 /**
268 * Includes admin css
269 *
270 * @link Codex reference: wp_enqueue_style()
271 *
272 * @since 1.1.0
273 */
274 function admin_css() {
275 wp_enqueue_style( 'arconix-shortcodes-admin', $this->url . 'includes/css/admin.css', false, self::VERSION );
276 }
277
278 function shortcodes_deactivate_add_questions ( $shortcodes_deactivate_questions ) {
279
280 $shortcodes_deactivate_questions = array(
281 0 => array(
282 'id' => 4,
283 'text' => __( "Font Awesome icons are not working.", "acs" ),
284 'input_type' => '',
285 'input_placeholder' => ''
286 ),
287 1 => array(
288 'id' => 5,
289 'text' => __( "Shortcode attributes does not work.", "acs" ),
290 'input_type' => 'textfield',
291 'input_placeholder' => 'Which attribute?'
292 ),
293 2 => array(
294 'id' => 6,
295 'text' => __( "The styling of the plugin does not work with my theme.", "acs" ),
296 'input_type' => 'textfield',
297 'input_placeholder' => 'Which Theme?'
298 ),
299 3 => array(
300 'id' => 7,
301 'text' => __( "The plugin is not compatible with another plugin.", "acs" ),
302 'input_type' => 'textfield',
303 'input_placeholder' => 'Which plugin?'
304 )
305
306 );
307 return $shortcodes_deactivate_questions;
308 }
309
310 function shortcodes_admin_actions ( ) {
311 /**
312 * We need to store the plugin version in DB, so we can show the welcome page and other contents.
313 */
314 $shortcodes_version_in_db = get_option( 'shortcodes_version' );
315 if ( $shortcodes_version_in_db != self::VERSION ){
316 update_option( 'shortcodes_version', self::VERSION );
317 }
318 }
319
320 /**
321 * Plugin's data to be tracked when Allow option is choosed.
322 *
323 * @hook ts_tracker_data
324 *
325 * @param array $data Contains the data to be tracked.
326 *
327 * @return array Plugin's data to track.
328 *
329 */
330
331 public static function shortcodes_ts_add_plugin_tracking_data ( $data ) {
332 if ( isset( $_GET[ 'shortcodes_tracker_optin' ] ) && isset( $_GET[ 'shortcodes_tracker_nonce' ] ) && wp_verify_nonce( $_GET[ 'shortcodes_tracker_nonce' ], 'shortcodes_tracker_optin' ) ) {
333
334 $plugin_data[ 'ts_meta_data_table_name' ] = 'ts_tracking_shortcodes_meta_data';
335 $plugin_data[ 'ts_plugin_name' ] = 'Arconix Shortcodes';
336 /**
337 * Add Plugin data
338 */
339 $plugin_data[ 'shortcodes_plugin_version' ] = self::VERSION;
340
341 $plugin_data[ 'shortcodes_allow_tracking' ] = get_option ( 'shortcodes_allow_tracking' );
342 $data[ 'plugin_data' ] = $plugin_data;
343 }
344 return $data;
345 }
346
347 /**
348 * Tracking data to send when No, thanks. button is clicked.
349 *
350 * @hook ts_tracker_opt_out_data
351 *
352 * @param array $params Parameters to pass for tracking data.
353 *
354 * @return array Data to track when opted out.
355 *
356 */
357 public static function shortcodes_get_data_for_opt_out ( $params ) {
358 $plugin_data[ 'ts_meta_data_table_name'] = 'ts_tracking_shortcodes_meta_data';
359 $plugin_data[ 'ts_plugin_name' ] = 'Arconix Shortcodes';
360
361 // Store count info
362 $params[ 'plugin_data' ] = $plugin_data;
363
364 return $params;
365 }
366
367 }
368
369 new Arconix_Shortcodes;