Version Description
- Fixed referrer issue
- Added popup button to easily add popups on posts/pages
Download this release
Release Info
Developer | timersys |
Plugin | Popups – WordPress Popup |
Version | 1.7 |
Comparing to | |
See all releases |
Code changes from version 1.6.0.1 to 1.7
- README.txt +20 -16
- admin/assets/js/popup.png +0 -0
- admin/assets/js/spu-tinymce.js +65 -0
- admin/class-social-popup-admin.php +89 -43
- admin/includes/tinymce-editor.php +50 -0
- popups.php +4 -4
- public/class-social-popup.php +44 -32
- public/includes/class-spu-rules.php +218 -214
README.txt
CHANGED
@@ -3,8 +3,8 @@ Contributors: timersys
|
|
3 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=K4T6L69EV9G2Q
|
4 |
Tags: popup,twitter,google+, facebook,Popups, twitter follow, facebook like, google plus,social boost, social splash, postmatic, mailpoet, facebook popup, scroll popups, popups, wordpress popup, wp popups, cf7, gf, gravity forms, contact form 7, ifs, infusion soft, subscribe, login popup, ajax login popups
|
5 |
Requires at least: 3.6
|
6 |
-
Tested up to: 4.
|
7 |
-
Stable tag: 1.
|
8 |
Text Domain: popups
|
9 |
License: GPLv2 or later
|
10 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
@@ -59,7 +59,7 @@ There are multiple display filters that can be combined:
|
|
59 |
* Shortcodes for social networks available
|
60 |
|
61 |
> <strong>Premium Version</strong><br>
|
62 |
-
>
|
63 |
> Check the **new premium version** available in ([https://wp.timersys.com/popups/](https://timersys.com/popups/?utm_source=readme%20file&utm_medium=readme%20links&utm_campaign=Popups%20Premium))
|
64 |
>
|
65 |
> * Beautiful optin forms for popular mail providers
|
@@ -80,17 +80,17 @@ There are multiple display filters that can be combined:
|
|
80 |
> * Ability to disable close button
|
81 |
> * Ability to disable Advanced close methods like esc or clicking outside of the popup
|
82 |
> * Premium support
|
83 |
-
>
|
84 |
|
85 |
= Plugin's Official Site =
|
86 |
|
87 |
Popups ([https://timersys.com/free-plugins/social-popup/](https://timersys.com/free-plugins/popups/))
|
88 |
|
89 |
-
= Github =
|
90 |
|
91 |
Fork me in https://github.com/timersys/popups/
|
92 |
|
93 |
-
= Available Languages =
|
94 |
|
95 |
* Serbo-Croatian - Borisa - http://www.webhostinghub.com/
|
96 |
* Spanish - Andrew Kurtis - http://www.webhostinghub.com/
|
@@ -195,6 +195,10 @@ If you have cache be sure to enable AJAX mode in the plugin settings page
|
|
195 |
|
196 |
== Changelog ==
|
197 |
|
|
|
|
|
|
|
|
|
198 |
= 1.6.0.1 =
|
199 |
* Fixed bug with manual triggering popup making all page cursor pointer
|
200 |
|
@@ -206,7 +210,7 @@ If you have cache be sure to enable AJAX mode in the plugin settings page
|
|
206 |
* Added query string display rule
|
207 |
* Added new cookie field to distinguish between conversion and impression
|
208 |
* Fixed jquery attached events not firing
|
209 |
-
* Improved queries
|
210 |
|
211 |
= 1.5.1 =
|
212 |
* Fixed grey screen of death that happened to some users. Sorry guys :(
|
@@ -435,17 +439,17 @@ If you have cache be sure to enable AJAX mode in the plugin settings page
|
|
435 |
|
436 |
* Added settings page
|
437 |
* Added option to disable auto style of shortcodes
|
438 |
-
* Plugin compatible with Popups Premium
|
439 |
* Minor bugfixes
|
440 |
* Js improvement
|
441 |
|
442 |
|
443 |
-
= 1.0.7 =
|
444 |
|
445 |
* Fixed bug with alignment in mobile devices
|
446 |
* Fixed bug in new aligning method for shortcodes
|
447 |
|
448 |
-
= 1.0.6 =
|
449 |
|
450 |
* Fixed locale problem with facebook js
|
451 |
* Fixed lang setting for Twitter Shortcode
|
@@ -453,23 +457,23 @@ If you have cache be sure to enable AJAX mode in the plugin settings page
|
|
453 |
* Changed method for aligning shortcodes for better compatibility
|
454 |
|
455 |
|
456 |
-
= 1.0.5 =
|
457 |
|
458 |
* Changed to only admins users can edit/create popups
|
459 |
* Fixed error that facebook layout were not working properly
|
460 |
* Added the ability to remove JS from facebook, twitter, and google by using variables
|
461 |
|
462 |
-
= 1.0.4 =
|
463 |
|
464 |
* Fixed bug that cookies where not set when user closes the box by clicking outside or with ESC key
|
465 |
|
466 |
-
= 1.0.3 =
|
467 |
|
468 |
* Fixed bug with popup on mobiles devices
|
469 |
* Css fixed for better alignment of social networks
|
470 |
* Added filters and actions for a future premium version of the plugin
|
471 |
|
472 |
-
= 1.0.2 =
|
473 |
|
474 |
* Added checks for shortcode values to avoid problems
|
475 |
* Changed style of Popup shortcodes help box to avoid problems
|
@@ -477,14 +481,14 @@ If you have cache be sure to enable AJAX mode in the plugin settings page
|
|
477 |
* Fixed the delete rule button that was missing
|
478 |
* Fixed Javascript error when editing popups
|
479 |
|
480 |
-
= 1.0.1 =
|
481 |
|
482 |
* Fixed mobile/tablets display rule and splitted in two new rules
|
483 |
* Changed cookie script to a small one
|
484 |
* Now public js is server minified
|
485 |
* Removed min-width from the popup
|
486 |
|
487 |
-
= 1.0.0 =
|
488 |
|
489 |
* Recoded from scratch. This is a totally new plugin
|
490 |
* Multiple popups are available now handled with custom post types
|
3 |
Donate link: https://www.paypal.com/cgi-bin/webscr?cmd=_s-xclick&hosted_button_id=K4T6L69EV9G2Q
|
4 |
Tags: popup,twitter,google+, facebook,Popups, twitter follow, facebook like, google plus,social boost, social splash, postmatic, mailpoet, facebook popup, scroll popups, popups, wordpress popup, wp popups, cf7, gf, gravity forms, contact form 7, ifs, infusion soft, subscribe, login popup, ajax login popups
|
5 |
Requires at least: 3.6
|
6 |
+
Tested up to: 4.7.1
|
7 |
+
Stable tag: 1.7
|
8 |
Text Domain: popups
|
9 |
License: GPLv2 or later
|
10 |
License URI: http://www.gnu.org/licenses/gpl-2.0.html
|
59 |
* Shortcodes for social networks available
|
60 |
|
61 |
> <strong>Premium Version</strong><br>
|
62 |
+
>
|
63 |
> Check the **new premium version** available in ([https://wp.timersys.com/popups/](https://timersys.com/popups/?utm_source=readme%20file&utm_medium=readme%20links&utm_campaign=Popups%20Premium))
|
64 |
>
|
65 |
> * Beautiful optin forms for popular mail providers
|
80 |
> * Ability to disable close button
|
81 |
> * Ability to disable Advanced close methods like esc or clicking outside of the popup
|
82 |
> * Premium support
|
83 |
+
>
|
84 |
|
85 |
= Plugin's Official Site =
|
86 |
|
87 |
Popups ([https://timersys.com/free-plugins/social-popup/](https://timersys.com/free-plugins/popups/))
|
88 |
|
89 |
+
= Github =
|
90 |
|
91 |
Fork me in https://github.com/timersys/popups/
|
92 |
|
93 |
+
= Available Languages =
|
94 |
|
95 |
* Serbo-Croatian - Borisa - http://www.webhostinghub.com/
|
96 |
* Spanish - Andrew Kurtis - http://www.webhostinghub.com/
|
195 |
|
196 |
== Changelog ==
|
197 |
|
198 |
+
= 1.7 =
|
199 |
+
* Fixed referrer issue
|
200 |
+
* Added popup button to easily add popups on posts/pages
|
201 |
+
|
202 |
= 1.6.0.1 =
|
203 |
* Fixed bug with manual triggering popup making all page cursor pointer
|
204 |
|
210 |
* Added query string display rule
|
211 |
* Added new cookie field to distinguish between conversion and impression
|
212 |
* Fixed jquery attached events not firing
|
213 |
+
* Improved queries
|
214 |
|
215 |
= 1.5.1 =
|
216 |
* Fixed grey screen of death that happened to some users. Sorry guys :(
|
439 |
|
440 |
* Added settings page
|
441 |
* Added option to disable auto style of shortcodes
|
442 |
+
* Plugin compatible with Popups Premium
|
443 |
* Minor bugfixes
|
444 |
* Js improvement
|
445 |
|
446 |
|
447 |
+
= 1.0.7 =
|
448 |
|
449 |
* Fixed bug with alignment in mobile devices
|
450 |
* Fixed bug in new aligning method for shortcodes
|
451 |
|
452 |
+
= 1.0.6 =
|
453 |
|
454 |
* Fixed locale problem with facebook js
|
455 |
* Fixed lang setting for Twitter Shortcode
|
457 |
* Changed method for aligning shortcodes for better compatibility
|
458 |
|
459 |
|
460 |
+
= 1.0.5 =
|
461 |
|
462 |
* Changed to only admins users can edit/create popups
|
463 |
* Fixed error that facebook layout were not working properly
|
464 |
* Added the ability to remove JS from facebook, twitter, and google by using variables
|
465 |
|
466 |
+
= 1.0.4 =
|
467 |
|
468 |
* Fixed bug that cookies where not set when user closes the box by clicking outside or with ESC key
|
469 |
|
470 |
+
= 1.0.3 =
|
471 |
|
472 |
* Fixed bug with popup on mobiles devices
|
473 |
* Css fixed for better alignment of social networks
|
474 |
* Added filters and actions for a future premium version of the plugin
|
475 |
|
476 |
+
= 1.0.2 =
|
477 |
|
478 |
* Added checks for shortcode values to avoid problems
|
479 |
* Changed style of Popup shortcodes help box to avoid problems
|
481 |
* Fixed the delete rule button that was missing
|
482 |
* Fixed Javascript error when editing popups
|
483 |
|
484 |
+
= 1.0.1 =
|
485 |
|
486 |
* Fixed mobile/tablets display rule and splitted in two new rules
|
487 |
* Changed cookie script to a small one
|
488 |
* Now public js is server minified
|
489 |
* Removed min-width from the popup
|
490 |
|
491 |
+
= 1.0.0 =
|
492 |
|
493 |
* Recoded from scratch. This is a totally new plugin
|
494 |
* Multiple popups are available now handled with custom post types
|
admin/assets/js/popup.png
ADDED
Binary file
|
admin/assets/js/spu-tinymce.js
ADDED
@@ -0,0 +1,65 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
(function( $ ) {
|
2 |
+
'use strict';
|
3 |
+
|
4 |
+
|
5 |
+
tinymce.create('tinymce.plugins.SPU', {
|
6 |
+
init : function(ed, url) {
|
7 |
+
ed.addButton('spu_button', {
|
8 |
+
title : 'Add Popup',
|
9 |
+
cmd : 'spu_button',
|
10 |
+
image : url+'/popup.png'
|
11 |
+
});
|
12 |
+
ed.addCommand('spu_button', function() {
|
13 |
+
|
14 |
+
jQuery('#spu_editor').dialog({
|
15 |
+
height: 500,
|
16 |
+
width: '600px',
|
17 |
+
buttons: {
|
18 |
+
"Insert Shortcode": function() {
|
19 |
+
|
20 |
+
var spu_id = jQuery('#spu-posts').val();
|
21 |
+
var str = "";
|
22 |
+
|
23 |
+
str = '[spu popup="'+spu_id+'"';
|
24 |
+
var selected_text = ed.selection.getContent();
|
25 |
+
if (selected_text) {
|
26 |
+
|
27 |
+
str += "]" + selected_text + "[/spu]";
|
28 |
+
|
29 |
+
} else {
|
30 |
+
|
31 |
+
str += "]YOUR TEXT OR IMG HERE[/spu]";
|
32 |
+
|
33 |
+
}
|
34 |
+
|
35 |
+
|
36 |
+
var Editor = tinyMCE.get('content');
|
37 |
+
Editor.focus();
|
38 |
+
Editor.selection.setContent(str);
|
39 |
+
|
40 |
+
|
41 |
+
jQuery( this ).dialog( "close" );
|
42 |
+
},
|
43 |
+
Cancel: function() {
|
44 |
+
jQuery( this ).dialog( "close" );
|
45 |
+
}
|
46 |
+
}
|
47 |
+
}).dialog('open');
|
48 |
+
|
49 |
+
});
|
50 |
+
},
|
51 |
+
createControl : function(n, cm) {
|
52 |
+
return null;
|
53 |
+
},
|
54 |
+
getInfo : function() {
|
55 |
+
return {
|
56 |
+
longname : 'Popups Button',
|
57 |
+
author : 'Damian Logghe',
|
58 |
+
authorurl : 'https://timersys.com',
|
59 |
+
infourl : 'http://wiki.moxiecode.com/index.php/TinyMCE:Plugins/example',
|
60 |
+
version : "0.1"
|
61 |
+
};
|
62 |
+
}
|
63 |
+
});
|
64 |
+
tinymce.PluginManager.add('spu', tinymce.plugins.SPU);
|
65 |
+
})( jQuery );
|
admin/class-social-popup-admin.php
CHANGED
@@ -62,7 +62,7 @@ class SocialPopup_Admin {
|
|
62 |
* @var bool
|
63 |
*/
|
64 |
protected $helper = '';
|
65 |
-
|
66 |
/**
|
67 |
* Initialize the plugin by loading admin scripts & styles and adding a
|
68 |
* settings page and menu.
|
@@ -80,7 +80,7 @@ class SocialPopup_Admin {
|
|
80 |
|
81 |
//settings name
|
82 |
$this->options_name = $this->plugin_slug .'_settings';
|
83 |
-
|
84 |
//load settings
|
85 |
$this->spu_settings = $plugin->get_settings();
|
86 |
|
@@ -110,13 +110,14 @@ class SocialPopup_Admin {
|
|
110 |
add_filter('spu/get_post_types', array($this, 'get_post_types'), 1, 3);
|
111 |
add_filter('spu/get_taxonomies', array($this, 'get_taxonomies'), 1, 3);
|
112 |
|
113 |
-
//AJAX Actions
|
114 |
add_action('wp_ajax_spu/field_group/render_rules', array( $this->helper, 'ajax_render_rules' ) );
|
115 |
add_action('wp_ajax_spu/field_group/render_operator', array( $this->helper, 'ajax_render_operator' ) );
|
116 |
|
117 |
//Tinymce
|
118 |
add_filter( 'tiny_mce_before_init', array($this, 'tinymce_init') );
|
119 |
add_action( 'admin_init', array( $this, 'editor_styles' ) );
|
|
|
120 |
|
121 |
//Columns in cpt
|
122 |
add_filter( 'manage_edit-spucpt_columns' , array( $this, 'set_custom_cpt_columns'), 10, 2 );
|
@@ -144,7 +145,7 @@ class SocialPopup_Admin {
|
|
144 |
|
145 |
return self::$instance;
|
146 |
}
|
147 |
-
|
148 |
|
149 |
/**
|
150 |
* Register custom post types
|
@@ -156,7 +157,7 @@ class SocialPopup_Admin {
|
|
156 |
if( class_exists('PopupsP') ){
|
157 |
$name .= ' - Premium v'. PopupsP::VERSION;
|
158 |
}
|
159 |
-
$name = apply_filters( 'spu/display/title', $name );
|
160 |
$labels = array(
|
161 |
'name' => $name,
|
162 |
'singular_name' => _x( 'Popups', 'post type singular name', 'popups' ),
|
@@ -202,7 +203,7 @@ class SocialPopup_Admin {
|
|
202 |
);
|
203 |
|
204 |
register_post_type( 'spucpt', $args );
|
205 |
-
|
206 |
}
|
207 |
|
208 |
/**
|
@@ -213,7 +214,7 @@ class SocialPopup_Admin {
|
|
213 |
public function add_settings_menu() {
|
214 |
|
215 |
add_submenu_page('edit.php?post_type=spucpt', __( 'Settings', 'popups' ), __( 'Settings', 'popups' ), apply_filters( 'spu/settings_page/roles', 'manage_options'), 'spu_settings', array( $this, 'settings_page' ) );
|
216 |
-
|
217 |
}
|
218 |
|
219 |
|
@@ -222,7 +223,7 @@ class SocialPopup_Admin {
|
|
222 |
* Settings page of the plugin
|
223 |
* @since 1.1
|
224 |
* @return void
|
225 |
-
*/
|
226 |
public function settings_page() {
|
227 |
|
228 |
$defaults = apply_filters( 'spu/settings_page/defaults_opts', array(
|
@@ -276,7 +277,7 @@ class SocialPopup_Admin {
|
|
276 |
'spucpt',
|
277 |
'normal',
|
278 |
'core'
|
279 |
-
);
|
280 |
|
281 |
add_meta_box(
|
282 |
'spu-appearance',
|
@@ -350,7 +351,7 @@ class SocialPopup_Admin {
|
|
350 |
public function popup_help( $post, $metabox ) {
|
351 |
|
352 |
include 'views/metaboxes/metabox-help.php';
|
353 |
-
}
|
354 |
/**
|
355 |
* Include the metabox view for popup rules
|
356 |
* @param object $post spucpt post object
|
@@ -362,7 +363,7 @@ class SocialPopup_Admin {
|
|
362 |
$groups = apply_filters('spu/metaboxes/get_box_rules', $this->helper->get_box_rules( $post->ID ), $post->ID);
|
363 |
|
364 |
include 'views/metaboxes/metabox-rules.php';
|
365 |
-
}
|
366 |
/**
|
367 |
* Include the metabox view for popup options
|
368 |
* @param object $post spucpt post object
|
@@ -370,7 +371,7 @@ class SocialPopup_Admin {
|
|
370 |
* @since 1.1
|
371 |
*/
|
372 |
public function popup_options( $post, $metabox ) {
|
373 |
-
|
374 |
$opts = apply_filters('spu/metaboxes/get_box_options', $this->helper->get_box_options( $post->ID ), $post->ID );
|
375 |
|
376 |
include 'views/metaboxes/metabox-options.php';
|
@@ -395,9 +396,9 @@ class SocialPopup_Admin {
|
|
395 |
* @since 1.1
|
396 |
*/
|
397 |
public function metabox_donate( $post, $metabox ) {
|
398 |
-
|
399 |
$donate_metabox = apply_filters( 'spu/metaboxes/donate_metabox', dirname(__FILE__) . '/views/metaboxes/metabox-donate.php' );
|
400 |
-
|
401 |
include $donate_metabox;
|
402 |
}
|
403 |
/**
|
@@ -407,9 +408,9 @@ class SocialPopup_Admin {
|
|
407 |
* @since 1.1
|
408 |
*/
|
409 |
public function metabox_support( $post, $metabox ) {
|
410 |
-
|
411 |
$support_metabox = apply_filters( 'spu/metaboxes/support_metabox', dirname(__FILE__) . '/views/metaboxes/metabox-support.php' );
|
412 |
-
|
413 |
include $support_metabox;
|
414 |
}
|
415 |
|
@@ -420,9 +421,9 @@ class SocialPopup_Admin {
|
|
420 |
* @since 1.1
|
421 |
*/
|
422 |
public function metabox_links( $post, $metabox ) {
|
423 |
-
|
424 |
$links_metabox = apply_filters( 'spu/metaboxes/links_metabox', dirname(__FILE__) . '/views/metaboxes/metabox-links.php' );
|
425 |
-
|
426 |
include $links_metabox;
|
427 |
}
|
428 |
|
@@ -459,7 +460,7 @@ class SocialPopup_Admin {
|
|
459 |
}
|
460 |
// same for posts revisions
|
461 |
if ( wp_is_post_revision( $post_id ) ) {
|
462 |
-
return $post_id;
|
463 |
}
|
464 |
|
465 |
// can user edit this post?
|
@@ -559,7 +560,7 @@ class SocialPopup_Admin {
|
|
559 |
}
|
560 |
wp_enqueue_style( 'spu-admin-css', plugins_url( 'assets/css/admin.css', __FILE__ ) , '', SocialPopup::VERSION );
|
561 |
wp_enqueue_style( 'wp-color-picker' );
|
562 |
-
|
563 |
}
|
564 |
|
565 |
/**
|
@@ -589,14 +590,14 @@ class SocialPopup_Admin {
|
|
589 |
wp_enqueue_script( 'spu-admin-js', plugins_url( 'assets/js/admin.js', __FILE__ ) , '', SocialPopup::VERSION );
|
590 |
|
591 |
wp_localize_script( 'spu-admin-js', 'spu_js',
|
592 |
-
array(
|
593 |
-
'admin_url' => admin_url( ),
|
594 |
'nonce' => wp_create_nonce( 'spu_nonce' ),
|
595 |
'l10n' => array (
|
596 |
'or' => '<span>'.__('OR', 'popups' ).'</span>'
|
597 |
),
|
598 |
'opts' => $this->helper->get_box_options($box_id)
|
599 |
-
)
|
600 |
);
|
601 |
|
602 |
wp_localize_script( 'spup-admin-js' , 'spup_js' ,
|
@@ -635,35 +636,35 @@ class SocialPopup_Admin {
|
|
635 |
* @return array Resulting cpts
|
636 |
*/
|
637 |
function get_post_types( $post_types, $exclude = array(), $include = array() ) {
|
638 |
-
|
639 |
// get all custom post types
|
640 |
$post_types = array_merge($post_types, get_post_types());
|
641 |
-
|
642 |
-
|
643 |
// core include / exclude
|
644 |
$spu_includes = array_merge( array(), $include );
|
645 |
$spu_excludes = array_merge( array( 'spucpt', 'acf', 'revision', 'nav_menu_item' ), $exclude );
|
646 |
-
|
647 |
-
|
648 |
// include
|
649 |
foreach( $spu_includes as $p )
|
650 |
-
{
|
651 |
if( post_type_exists($p) )
|
652 |
-
{
|
653 |
$post_types[ $p ] = $p;
|
654 |
}
|
655 |
}
|
656 |
-
|
657 |
-
|
658 |
// exclude
|
659 |
foreach( $spu_excludes as $p )
|
660 |
{
|
661 |
unset( $post_types[ $p ] );
|
662 |
}
|
663 |
-
|
664 |
-
|
665 |
return $post_types;
|
666 |
-
|
667 |
}
|
668 |
|
669 |
/**
|
@@ -674,12 +675,12 @@ class SocialPopup_Admin {
|
|
674 |
*
|
675 |
* @return array [type] [description]
|
676 |
*/
|
677 |
-
function get_taxonomies( $choices, $simple_value = false ) {
|
678 |
-
|
679 |
// vars
|
680 |
$post_types = get_post_types();
|
681 |
-
|
682 |
-
|
683 |
if($post_types)
|
684 |
{
|
685 |
foreach($post_types as $post_type)
|
@@ -697,20 +698,20 @@ class SocialPopup_Admin {
|
|
697 |
foreach($terms as $term)
|
698 |
{
|
699 |
$value = $taxonomy . ':' . $term->term_id;
|
700 |
-
|
701 |
if( $simple_value )
|
702 |
{
|
703 |
$value = $term->term_id;
|
704 |
}
|
705 |
-
|
706 |
-
$choices[$post_type_object->label . ': ' . $taxonomy][$value] = $term->name;
|
707 |
}
|
708 |
}
|
709 |
}
|
710 |
}
|
711 |
}
|
712 |
}
|
713 |
-
|
714 |
return $choices;
|
715 |
}
|
716 |
|
@@ -735,11 +736,18 @@ class SocialPopup_Admin {
|
|
735 |
* @since 1.2.3.6
|
736 |
*/
|
737 |
function editor_styles() {
|
|
|
738 |
$post_type = isset($_GET['post']) ? get_post_type($_GET['post']) : '';
|
739 |
|
740 |
if( 'spucpt' == $post_type || get_post_type() == 'spucpt' || (isset( $_GET['post_type']) && $_GET['post_type'] == 'spucpt') ) {
|
741 |
add_editor_style( SPU_PLUGIN_URL . 'admin/assets/css/editor-style.css' );
|
742 |
}
|
|
|
|
|
|
|
|
|
|
|
|
|
743 |
}
|
744 |
|
745 |
function get_rules_choices() {
|
@@ -899,4 +907,42 @@ class SocialPopup_Admin {
|
|
899 |
return $actions;
|
900 |
}
|
901 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
902 |
}
|
62 |
* @var bool
|
63 |
*/
|
64 |
protected $helper = '';
|
65 |
+
|
66 |
/**
|
67 |
* Initialize the plugin by loading admin scripts & styles and adding a
|
68 |
* settings page and menu.
|
80 |
|
81 |
//settings name
|
82 |
$this->options_name = $this->plugin_slug .'_settings';
|
83 |
+
|
84 |
//load settings
|
85 |
$this->spu_settings = $plugin->get_settings();
|
86 |
|
110 |
add_filter('spu/get_post_types', array($this, 'get_post_types'), 1, 3);
|
111 |
add_filter('spu/get_taxonomies', array($this, 'get_taxonomies'), 1, 3);
|
112 |
|
113 |
+
//AJAX Actions
|
114 |
add_action('wp_ajax_spu/field_group/render_rules', array( $this->helper, 'ajax_render_rules' ) );
|
115 |
add_action('wp_ajax_spu/field_group/render_operator', array( $this->helper, 'ajax_render_operator' ) );
|
116 |
|
117 |
//Tinymce
|
118 |
add_filter( 'tiny_mce_before_init', array($this, 'tinymce_init') );
|
119 |
add_action( 'admin_init', array( $this, 'editor_styles' ) );
|
120 |
+
add_action( 'init', array( $this, 'register_tiny_buttons' ) );
|
121 |
|
122 |
//Columns in cpt
|
123 |
add_filter( 'manage_edit-spucpt_columns' , array( $this, 'set_custom_cpt_columns'), 10, 2 );
|
145 |
|
146 |
return self::$instance;
|
147 |
}
|
148 |
+
|
149 |
|
150 |
/**
|
151 |
* Register custom post types
|
157 |
if( class_exists('PopupsP') ){
|
158 |
$name .= ' - Premium v'. PopupsP::VERSION;
|
159 |
}
|
160 |
+
$name = apply_filters( 'spu/display/title', $name );
|
161 |
$labels = array(
|
162 |
'name' => $name,
|
163 |
'singular_name' => _x( 'Popups', 'post type singular name', 'popups' ),
|
203 |
);
|
204 |
|
205 |
register_post_type( 'spucpt', $args );
|
206 |
+
|
207 |
}
|
208 |
|
209 |
/**
|
214 |
public function add_settings_menu() {
|
215 |
|
216 |
add_submenu_page('edit.php?post_type=spucpt', __( 'Settings', 'popups' ), __( 'Settings', 'popups' ), apply_filters( 'spu/settings_page/roles', 'manage_options'), 'spu_settings', array( $this, 'settings_page' ) );
|
217 |
+
|
218 |
}
|
219 |
|
220 |
|
223 |
* Settings page of the plugin
|
224 |
* @since 1.1
|
225 |
* @return void
|
226 |
+
*/
|
227 |
public function settings_page() {
|
228 |
|
229 |
$defaults = apply_filters( 'spu/settings_page/defaults_opts', array(
|
277 |
'spucpt',
|
278 |
'normal',
|
279 |
'core'
|
280 |
+
);
|
281 |
|
282 |
add_meta_box(
|
283 |
'spu-appearance',
|
351 |
public function popup_help( $post, $metabox ) {
|
352 |
|
353 |
include 'views/metaboxes/metabox-help.php';
|
354 |
+
}
|
355 |
/**
|
356 |
* Include the metabox view for popup rules
|
357 |
* @param object $post spucpt post object
|
363 |
$groups = apply_filters('spu/metaboxes/get_box_rules', $this->helper->get_box_rules( $post->ID ), $post->ID);
|
364 |
|
365 |
include 'views/metaboxes/metabox-rules.php';
|
366 |
+
}
|
367 |
/**
|
368 |
* Include the metabox view for popup options
|
369 |
* @param object $post spucpt post object
|
371 |
* @since 1.1
|
372 |
*/
|
373 |
public function popup_options( $post, $metabox ) {
|
374 |
+
|
375 |
$opts = apply_filters('spu/metaboxes/get_box_options', $this->helper->get_box_options( $post->ID ), $post->ID );
|
376 |
|
377 |
include 'views/metaboxes/metabox-options.php';
|
396 |
* @since 1.1
|
397 |
*/
|
398 |
public function metabox_donate( $post, $metabox ) {
|
399 |
+
|
400 |
$donate_metabox = apply_filters( 'spu/metaboxes/donate_metabox', dirname(__FILE__) . '/views/metaboxes/metabox-donate.php' );
|
401 |
+
|
402 |
include $donate_metabox;
|
403 |
}
|
404 |
/**
|
408 |
* @since 1.1
|
409 |
*/
|
410 |
public function metabox_support( $post, $metabox ) {
|
411 |
+
|
412 |
$support_metabox = apply_filters( 'spu/metaboxes/support_metabox', dirname(__FILE__) . '/views/metaboxes/metabox-support.php' );
|
413 |
+
|
414 |
include $support_metabox;
|
415 |
}
|
416 |
|
421 |
* @since 1.1
|
422 |
*/
|
423 |
public function metabox_links( $post, $metabox ) {
|
424 |
+
|
425 |
$links_metabox = apply_filters( 'spu/metaboxes/links_metabox', dirname(__FILE__) . '/views/metaboxes/metabox-links.php' );
|
426 |
+
|
427 |
include $links_metabox;
|
428 |
}
|
429 |
|
460 |
}
|
461 |
// same for posts revisions
|
462 |
if ( wp_is_post_revision( $post_id ) ) {
|
463 |
+
return $post_id;
|
464 |
}
|
465 |
|
466 |
// can user edit this post?
|
560 |
}
|
561 |
wp_enqueue_style( 'spu-admin-css', plugins_url( 'assets/css/admin.css', __FILE__ ) , '', SocialPopup::VERSION );
|
562 |
wp_enqueue_style( 'wp-color-picker' );
|
563 |
+
|
564 |
}
|
565 |
|
566 |
/**
|
590 |
wp_enqueue_script( 'spu-admin-js', plugins_url( 'assets/js/admin.js', __FILE__ ) , '', SocialPopup::VERSION );
|
591 |
|
592 |
wp_localize_script( 'spu-admin-js', 'spu_js',
|
593 |
+
array(
|
594 |
+
'admin_url' => admin_url( ),
|
595 |
'nonce' => wp_create_nonce( 'spu_nonce' ),
|
596 |
'l10n' => array (
|
597 |
'or' => '<span>'.__('OR', 'popups' ).'</span>'
|
598 |
),
|
599 |
'opts' => $this->helper->get_box_options($box_id)
|
600 |
+
)
|
601 |
);
|
602 |
|
603 |
wp_localize_script( 'spup-admin-js' , 'spup_js' ,
|
636 |
* @return array Resulting cpts
|
637 |
*/
|
638 |
function get_post_types( $post_types, $exclude = array(), $include = array() ) {
|
639 |
+
|
640 |
// get all custom post types
|
641 |
$post_types = array_merge($post_types, get_post_types());
|
642 |
+
|
643 |
+
|
644 |
// core include / exclude
|
645 |
$spu_includes = array_merge( array(), $include );
|
646 |
$spu_excludes = array_merge( array( 'spucpt', 'acf', 'revision', 'nav_menu_item' ), $exclude );
|
647 |
+
|
648 |
+
|
649 |
// include
|
650 |
foreach( $spu_includes as $p )
|
651 |
+
{
|
652 |
if( post_type_exists($p) )
|
653 |
+
{
|
654 |
$post_types[ $p ] = $p;
|
655 |
}
|
656 |
}
|
657 |
+
|
658 |
+
|
659 |
// exclude
|
660 |
foreach( $spu_excludes as $p )
|
661 |
{
|
662 |
unset( $post_types[ $p ] );
|
663 |
}
|
664 |
+
|
665 |
+
|
666 |
return $post_types;
|
667 |
+
|
668 |
}
|
669 |
|
670 |
/**
|
675 |
*
|
676 |
* @return array [type] [description]
|
677 |
*/
|
678 |
+
function get_taxonomies( $choices, $simple_value = false ) {
|
679 |
+
|
680 |
// vars
|
681 |
$post_types = get_post_types();
|
682 |
+
|
683 |
+
|
684 |
if($post_types)
|
685 |
{
|
686 |
foreach($post_types as $post_type)
|
698 |
foreach($terms as $term)
|
699 |
{
|
700 |
$value = $taxonomy . ':' . $term->term_id;
|
701 |
+
|
702 |
if( $simple_value )
|
703 |
{
|
704 |
$value = $term->term_id;
|
705 |
}
|
706 |
+
|
707 |
+
$choices[$post_type_object->label . ': ' . $taxonomy][$value] = $term->name;
|
708 |
}
|
709 |
}
|
710 |
}
|
711 |
}
|
712 |
}
|
713 |
}
|
714 |
+
|
715 |
return $choices;
|
716 |
}
|
717 |
|
736 |
* @since 1.2.3.6
|
737 |
*/
|
738 |
function editor_styles() {
|
739 |
+
global $pagenow;
|
740 |
$post_type = isset($_GET['post']) ? get_post_type($_GET['post']) : '';
|
741 |
|
742 |
if( 'spucpt' == $post_type || get_post_type() == 'spucpt' || (isset( $_GET['post_type']) && $_GET['post_type'] == 'spucpt') ) {
|
743 |
add_editor_style( SPU_PLUGIN_URL . 'admin/assets/css/editor-style.css' );
|
744 |
}
|
745 |
+
// Add html for shortcodes popup
|
746 |
+
if( 'post.php' == $pagenow || 'post-new.php' == $pagenow ) {
|
747 |
+
|
748 |
+
add_action( 'in_admin_footer', array($this, 'add_editor' ) );
|
749 |
+
|
750 |
+
}
|
751 |
}
|
752 |
|
753 |
function get_rules_choices() {
|
907 |
return $actions;
|
908 |
}
|
909 |
|
910 |
+
/**
|
911 |
+
* Add filters for tinymce buttons
|
912 |
+
*/
|
913 |
+
public function register_tiny_buttons() {
|
914 |
+
add_filter( "mce_external_plugins", array( $this, "add_button" ) );
|
915 |
+
add_filter( 'mce_buttons', array( $this, 'register_button' ) );
|
916 |
+
}
|
917 |
+
|
918 |
+
/**
|
919 |
+
* Add buton js file
|
920 |
+
* @param [type] $plugin_array [description]
|
921 |
+
*/
|
922 |
+
function add_button( $plugin_array ) {
|
923 |
+
|
924 |
+
$plugin_array['spu'] = plugins_url( 'assets/js/spu-tinymce.js' , __FILE__ );
|
925 |
+
return $plugin_array;
|
926 |
+
|
927 |
+
}
|
928 |
+
|
929 |
+
/**
|
930 |
+
* Register button
|
931 |
+
* @param [type] $buttons [description]
|
932 |
+
* @return [type] [description]
|
933 |
+
*/
|
934 |
+
function register_button( $buttons ) {
|
935 |
+
array_push( $buttons, '|', 'spu_button' ); // dropcap', 'recentposts
|
936 |
+
return $buttons;
|
937 |
+
}
|
938 |
+
|
939 |
+
/**
|
940 |
+
* Add popup editor for
|
941 |
+
*/
|
942 |
+
function add_editor() {
|
943 |
+
|
944 |
+
include 'includes/tinymce-editor.php';
|
945 |
+
|
946 |
+
}
|
947 |
+
|
948 |
}
|
admin/includes/tinymce-editor.php
ADDED
@@ -0,0 +1,50 @@
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
1 |
+
<form name="form" autocomplete="off">
|
2 |
+
<div id="spu_editor" class="shortcode_editor" title="Insert popup link to page" style="display:none;height:500px">
|
3 |
+
<div style="display: none;"><!--hack for chrome-->
|
4 |
+
<input type="text" id="PreventChromeAutocomplete" name="PreventChromeAutocomplete" autocomplete="address-level4" />
|
5 |
+
</div>
|
6 |
+
<table class="form-table">
|
7 |
+
<tr>
|
8 |
+
<td colspan="2">
|
9 |
+
<p>
|
10 |
+
<?php _e('Choose which popup you want to insert. This will generate an href link that you can use with text or images', 'spu');?>
|
11 |
+
</p>
|
12 |
+
</td>
|
13 |
+
</tr>
|
14 |
+
<tr>
|
15 |
+
<th><label for="spu_what"><?php _e( 'Choose:', 'spu' ); ?></label></th>
|
16 |
+
<td>
|
17 |
+
<select name="spu-post" id="spu-posts">
|
18 |
+
<option value="">
|
19 |
+
<?php _e('Choose one','spu');?>
|
20 |
+
</option>
|
21 |
+
<?php
|
22 |
+
// WP_Query arguments
|
23 |
+
$args = array(
|
24 |
+
'post_type' => array( 'spucpt' ),
|
25 |
+
'post_status' => array( 'publish' ),
|
26 |
+
'posts_per_page' => '-1',
|
27 |
+
);
|
28 |
+
|
29 |
+
// The Query
|
30 |
+
$query = new WP_Query( $args );
|
31 |
+
|
32 |
+
// The Loop
|
33 |
+
if ( $query->have_posts() ) {
|
34 |
+
while ( $query->have_posts() ) {
|
35 |
+
$query->the_post();
|
36 |
+
echo '<option value="'.get_the_id().'">'.get_the_title().'</option>"';
|
37 |
+
}
|
38 |
+
} else {
|
39 |
+
// no posts found
|
40 |
+
}
|
41 |
+
|
42 |
+
// Restore original Post Data
|
43 |
+
wp_reset_postdata();
|
44 |
+
?>
|
45 |
+
</td>
|
46 |
+
</tr>
|
47 |
+
|
48 |
+
</table>
|
49 |
+
</div>
|
50 |
+
</form>
|
popups.php
CHANGED
@@ -1,6 +1,6 @@
|
|
1 |
<?php
|
2 |
/**
|
3 |
-
* Popups
|
4 |
*
|
5 |
* @package socialpopup
|
6 |
* @author Damian Logghe <info@timersys.com>
|
@@ -11,7 +11,7 @@
|
|
11 |
* @socialpopup
|
12 |
* Plugin Name: Popups - WordPress Popup
|
13 |
* Plugin URI: http://www.timersys.com/free-plugins/social-popup/
|
14 |
-
* Version: 1.
|
15 |
* Description: Most complete free Popups plugin, scroll triggered popups, compatible with social networks, Gravity Forms, Ninja Forms, Contact form 7, Mailpoet, Mailchimp for WP, Postmatic, etc
|
16 |
* Author: Damian Logghe
|
17 |
* Author URI: https://timersys.com
|
@@ -30,7 +30,7 @@ if ( ! defined( 'WPINC' ) ) {
|
|
30 |
* Public-Facing Functionality
|
31 |
*----------------------------------------------------------------------------*/
|
32 |
|
33 |
-
define( 'SPU_VERSION' , '1.
|
34 |
define( 'SPU_PLUGIN_DIR' , plugin_dir_path(__FILE__) );
|
35 |
define( 'SPU_PLUGIN_URL' , plugin_dir_url(__FILE__) );
|
36 |
define( 'SPU_PLUGIN_HOOK' , basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ) );
|
@@ -74,4 +74,4 @@ if ( is_admin() ) {
|
|
74 |
if( get_option('spu_plugin_updated') && !get_option('spu_rate_plugin') )
|
75 |
add_action( 'admin_notices', array( $spu_notices, 'rate_plugin') );
|
76 |
|
77 |
-
}
|
1 |
<?php
|
2 |
/**
|
3 |
+
* Popups
|
4 |
*
|
5 |
* @package socialpopup
|
6 |
* @author Damian Logghe <info@timersys.com>
|
11 |
* @socialpopup
|
12 |
* Plugin Name: Popups - WordPress Popup
|
13 |
* Plugin URI: http://www.timersys.com/free-plugins/social-popup/
|
14 |
+
* Version: 1.7
|
15 |
* Description: Most complete free Popups plugin, scroll triggered popups, compatible with social networks, Gravity Forms, Ninja Forms, Contact form 7, Mailpoet, Mailchimp for WP, Postmatic, etc
|
16 |
* Author: Damian Logghe
|
17 |
* Author URI: https://timersys.com
|
30 |
* Public-Facing Functionality
|
31 |
*----------------------------------------------------------------------------*/
|
32 |
|
33 |
+
define( 'SPU_VERSION' , '1.7' );
|
34 |
define( 'SPU_PLUGIN_DIR' , plugin_dir_path(__FILE__) );
|
35 |
define( 'SPU_PLUGIN_URL' , plugin_dir_url(__FILE__) );
|
36 |
define( 'SPU_PLUGIN_HOOK' , basename( dirname( __FILE__ ) ) . '/' . basename( __FILE__ ) );
|
74 |
if( get_option('spu_plugin_updated') && !get_option('spu_rate_plugin') )
|
75 |
add_action( 'admin_notices', array( $spu_notices, 'rate_plugin') );
|
76 |
|
77 |
+
}
|
public/class-social-popup.php
CHANGED
@@ -124,6 +124,7 @@ class SocialPopup {
|
|
124 |
add_shortcode( 'spu-twitter', array( $this, 'twitter_shortcode' ) );
|
125 |
add_shortcode( 'spu-google', array( $this, 'google_shortcode' ) );
|
126 |
add_shortcode( 'spu-close', array( $this, 'close_shortcode' ) );
|
|
|
127 |
}
|
128 |
|
129 |
/**
|
@@ -288,7 +289,7 @@ class SocialPopup {
|
|
288 |
<p style="text-align: center;">If you like this site please help and make click on any of these buttons!</p>
|
289 |
<p style="text-align: center;">[spu-facebook][spu-google][spu-twitter]</p>';
|
290 |
$defaults = array(
|
291 |
-
'post_status' => 'draft',
|
292 |
'post_type' => 'spucpt',
|
293 |
'post_content' => $post_content,
|
294 |
'post_title' => 'Popups Example'
|
@@ -349,13 +350,13 @@ class SocialPopup {
|
|
349 |
}
|
350 |
|
351 |
wp_register_style( 'spu-public-css', plugins_url( 'assets/css/public.css', __FILE__ ), array(), self::VERSION );
|
352 |
-
|
353 |
wp_register_script( $handle, $js_url, array( 'jquery' ), self::VERSION, true );
|
354 |
-
|
355 |
wp_register_script( 'spu-facebook', '//connect.facebook.net/'.get_locale().'/sdk.js#xfbml=1&version=v2.3', array('jquery'), null, FALSE);
|
356 |
|
357 |
wp_register_script( 'spu-twitter', '//platform.twitter.com/widgets.js', array('jquery'), self::VERSION, FALSE);
|
358 |
-
|
359 |
wp_register_script( 'spu-google', '//apis.google.com/js/plusone.js', array('jquery'), self::VERSION, FALSE);
|
360 |
|
361 |
}
|
@@ -500,7 +501,7 @@ class SocialPopup {
|
|
500 |
* @return string [description]
|
501 |
*/
|
502 |
function facebook_shortcode( $atts, $content ) {
|
503 |
-
|
504 |
extract( shortcode_atts( array(
|
505 |
'href' => apply_filters( 'spu/social/fb_href', 'https://www.facebook.com/pages/Timersys/146687622031640' ),
|
506 |
'layout' => 'button_count', // standard, box_count, button_count, button
|
@@ -509,7 +510,7 @@ class SocialPopup {
|
|
509 |
'action' => 'like', // recommend
|
510 |
'width' => '',
|
511 |
), $atts ) );
|
512 |
-
|
513 |
$layout = strtolower( trim( $layout ) );
|
514 |
$action = strtolower( trim( $action ) );
|
515 |
|
@@ -563,7 +564,7 @@ class SocialPopup {
|
|
563 |
'size' => '', // large
|
564 |
'lang' => '',
|
565 |
), $atts ) );
|
566 |
-
|
567 |
return '<div class="spu-twitter spu-shortcode"><a href="https://twitter.com/'.$user.'" class="twitter-follow-button" data-show-count="'.strtolower( trim( $show_count ) ).'" data-size="'.strtolower( trim( $size ) ).'" data-lang="'.$lang.'"></a></div>';
|
568 |
|
569 |
}
|
@@ -578,7 +579,7 @@ class SocialPopup {
|
|
578 |
extract( shortcode_atts( array(
|
579 |
'size' => 'medium', //small standard tall
|
580 |
'annotation' => 'bubble', //inline none
|
581 |
-
'url' => apply_filters( 'spu/social/gp_url', 'https://plus.google.com/u/0/103508783120806246698/posts' ),
|
582 |
), $atts ) );
|
583 |
|
584 |
$size = strtolower( trim( $size ) );
|
@@ -587,26 +588,26 @@ class SocialPopup {
|
|
587 |
//to avoid problems
|
588 |
if( 'medium' != $size && 'small' != $size && 'standard' != $size && 'tall' != $size ) {
|
589 |
$size = 'medium';
|
590 |
-
}
|
591 |
if( 'bubble' != $annotation && 'inline' != $annotation && 'none' != $annotation ) {
|
592 |
$annotation = 'bubble';
|
593 |
}
|
594 |
|
595 |
return '<div class="spu-google spu-shortcode"><div class="g-plusone" data-callback="googleCB" data-onendinteraction="closeGoogle" data-recommendations="false" data-annotation="'.$annotation.'" data-size="'.$size.'" data-href="'.$url.'"></div></div>';
|
596 |
-
|
597 |
}
|
598 |
|
599 |
function close_shortcode( $atts, $content ) {
|
600 |
extract( shortcode_atts( array(
|
601 |
-
'class' => 'button-primary',
|
602 |
'text' => 'Close',
|
603 |
), $atts ) );
|
604 |
|
605 |
return '<button class="spu-close-popup '.$class.'">'.$text.'</button>';
|
606 |
-
}
|
607 |
-
|
608 |
/**
|
609 |
-
* Returns plugin info
|
610 |
* @param string $i info name
|
611 |
* @return mixed one all or none
|
612 |
*/
|
@@ -614,22 +615,22 @@ class SocialPopup {
|
|
614 |
{
|
615 |
// vars
|
616 |
$return = false;
|
617 |
-
|
618 |
-
|
619 |
// specific
|
620 |
if( isset($this->info[ $i ]) )
|
621 |
{
|
622 |
$return = $this->info[ $i ];
|
623 |
}
|
624 |
-
|
625 |
-
|
626 |
// all
|
627 |
if( $i == 'all' )
|
628 |
{
|
629 |
$return = $this->info;
|
630 |
}
|
631 |
-
|
632 |
-
|
633 |
// return
|
634 |
return $return;
|
635 |
}
|
@@ -644,16 +645,16 @@ class SocialPopup {
|
|
644 |
|
645 |
//if we have matches continue
|
646 |
if( ! empty( $spu_matches) ) {
|
647 |
-
|
648 |
foreach ($spu_matches as $spu_id ) {
|
649 |
|
650 |
include( 'views/popup.php');
|
651 |
|
652 |
} //endforeach
|
653 |
echo '<div id="fb-root" class=" fb_reset"></div>';
|
654 |
-
|
655 |
-
}
|
656 |
-
|
657 |
}
|
658 |
|
659 |
/**
|
@@ -689,7 +690,7 @@ class SocialPopup {
|
|
689 |
|
690 |
define( 'DOING_AJAX', TRUE );
|
691 |
|
692 |
-
$this->print_boxes();
|
693 |
|
694 |
die();
|
695 |
}
|
@@ -706,13 +707,14 @@ class SocialPopup {
|
|
706 |
if ( ! empty( $wpml_settings['custom_posts_sync_option']['spucpt'] ) ) {
|
707 |
|
708 |
$lang_code = isset( $_GET['lang'] ) ? $_GET['lang'] : ICL_LANGUAGE_CODE;
|
709 |
-
$sql = "
|
710 |
-
|
711 |
-
|
712 |
-
|
713 |
-
|
714 |
-
|
715 |
-
|
|
|
716 |
|
717 |
$ids = $wpdb->get_results( $sql );
|
718 |
if( !empty($ids) )
|
@@ -722,4 +724,14 @@ class SocialPopup {
|
|
722 |
return false;
|
723 |
}
|
724 |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
725 |
}
|
124 |
add_shortcode( 'spu-twitter', array( $this, 'twitter_shortcode' ) );
|
125 |
add_shortcode( 'spu-google', array( $this, 'google_shortcode' ) );
|
126 |
add_shortcode( 'spu-close', array( $this, 'close_shortcode' ) );
|
127 |
+
add_shortcode( 'spu', array( $this, 'popup_link_shortcode' ) );
|
128 |
}
|
129 |
|
130 |
/**
|
289 |
<p style="text-align: center;">If you like this site please help and make click on any of these buttons!</p>
|
290 |
<p style="text-align: center;">[spu-facebook][spu-google][spu-twitter]</p>';
|
291 |
$defaults = array(
|
292 |
+
'post_status' => 'draft',
|
293 |
'post_type' => 'spucpt',
|
294 |
'post_content' => $post_content,
|
295 |
'post_title' => 'Popups Example'
|
350 |
}
|
351 |
|
352 |
wp_register_style( 'spu-public-css', plugins_url( 'assets/css/public.css', __FILE__ ), array(), self::VERSION );
|
353 |
+
|
354 |
wp_register_script( $handle, $js_url, array( 'jquery' ), self::VERSION, true );
|
355 |
+
|
356 |
wp_register_script( 'spu-facebook', '//connect.facebook.net/'.get_locale().'/sdk.js#xfbml=1&version=v2.3', array('jquery'), null, FALSE);
|
357 |
|
358 |
wp_register_script( 'spu-twitter', '//platform.twitter.com/widgets.js', array('jquery'), self::VERSION, FALSE);
|
359 |
+
|
360 |
wp_register_script( 'spu-google', '//apis.google.com/js/plusone.js', array('jquery'), self::VERSION, FALSE);
|
361 |
|
362 |
}
|
501 |
* @return string [description]
|
502 |
*/
|
503 |
function facebook_shortcode( $atts, $content ) {
|
504 |
+
|
505 |
extract( shortcode_atts( array(
|
506 |
'href' => apply_filters( 'spu/social/fb_href', 'https://www.facebook.com/pages/Timersys/146687622031640' ),
|
507 |
'layout' => 'button_count', // standard, box_count, button_count, button
|
510 |
'action' => 'like', // recommend
|
511 |
'width' => '',
|
512 |
), $atts ) );
|
513 |
+
|
514 |
$layout = strtolower( trim( $layout ) );
|
515 |
$action = strtolower( trim( $action ) );
|
516 |
|
564 |
'size' => '', // large
|
565 |
'lang' => '',
|
566 |
), $atts ) );
|
567 |
+
|
568 |
return '<div class="spu-twitter spu-shortcode"><a href="https://twitter.com/'.$user.'" class="twitter-follow-button" data-show-count="'.strtolower( trim( $show_count ) ).'" data-size="'.strtolower( trim( $size ) ).'" data-lang="'.$lang.'"></a></div>';
|
569 |
|
570 |
}
|
579 |
extract( shortcode_atts( array(
|
580 |
'size' => 'medium', //small standard tall
|
581 |
'annotation' => 'bubble', //inline none
|
582 |
+
'url' => apply_filters( 'spu/social/gp_url', 'https://plus.google.com/u/0/103508783120806246698/posts' ),
|
583 |
), $atts ) );
|
584 |
|
585 |
$size = strtolower( trim( $size ) );
|
588 |
//to avoid problems
|
589 |
if( 'medium' != $size && 'small' != $size && 'standard' != $size && 'tall' != $size ) {
|
590 |
$size = 'medium';
|
591 |
+
}
|
592 |
if( 'bubble' != $annotation && 'inline' != $annotation && 'none' != $annotation ) {
|
593 |
$annotation = 'bubble';
|
594 |
}
|
595 |
|
596 |
return '<div class="spu-google spu-shortcode"><div class="g-plusone" data-callback="googleCB" data-onendinteraction="closeGoogle" data-recommendations="false" data-annotation="'.$annotation.'" data-size="'.$size.'" data-href="'.$url.'"></div></div>';
|
597 |
+
|
598 |
}
|
599 |
|
600 |
function close_shortcode( $atts, $content ) {
|
601 |
extract( shortcode_atts( array(
|
602 |
+
'class' => 'button-primary',
|
603 |
'text' => 'Close',
|
604 |
), $atts ) );
|
605 |
|
606 |
return '<button class="spu-close-popup '.$class.'">'.$text.'</button>';
|
607 |
+
}
|
608 |
+
|
609 |
/**
|
610 |
+
* Returns plugin info
|
611 |
* @param string $i info name
|
612 |
* @return mixed one all or none
|
613 |
*/
|
615 |
{
|
616 |
// vars
|
617 |
$return = false;
|
618 |
+
|
619 |
+
|
620 |
// specific
|
621 |
if( isset($this->info[ $i ]) )
|
622 |
{
|
623 |
$return = $this->info[ $i ];
|
624 |
}
|
625 |
+
|
626 |
+
|
627 |
// all
|
628 |
if( $i == 'all' )
|
629 |
{
|
630 |
$return = $this->info;
|
631 |
}
|
632 |
+
|
633 |
+
|
634 |
// return
|
635 |
return $return;
|
636 |
}
|
645 |
|
646 |
//if we have matches continue
|
647 |
if( ! empty( $spu_matches) ) {
|
648 |
+
|
649 |
foreach ($spu_matches as $spu_id ) {
|
650 |
|
651 |
include( 'views/popup.php');
|
652 |
|
653 |
} //endforeach
|
654 |
echo '<div id="fb-root" class=" fb_reset"></div>';
|
655 |
+
|
656 |
+
}
|
657 |
+
|
658 |
}
|
659 |
|
660 |
/**
|
690 |
|
691 |
define( 'DOING_AJAX', TRUE );
|
692 |
|
693 |
+
$this->print_boxes();
|
694 |
|
695 |
die();
|
696 |
}
|
707 |
if ( ! empty( $wpml_settings['custom_posts_sync_option']['spucpt'] ) ) {
|
708 |
|
709 |
$lang_code = isset( $_GET['lang'] ) ? $_GET['lang'] : ICL_LANGUAGE_CODE;
|
710 |
+
$sql = "SELECT DISTINCT ID, post_content,
|
711 |
+
MAX(CASE WHEN pm1.meta_key = 'spu_rules' then pm1.meta_value ELSE NULL END) as spu_rules,
|
712 |
+
MAX(CASE WHEN pm1.meta_key = 'spu_ab_parent' then pm1.meta_value ELSE NULL END) as spu_ab_parent
|
713 |
+
FROM $wpdb->posts p
|
714 |
+
LEFT JOIN $wpdb->postmeta pm1 ON ( pm1.post_id = p.ID)
|
715 |
+
LEFT JOIN {$wpdb->prefix}icl_translations as b ON p.ID = b.element_id
|
716 |
+
WHERE post_type='spucpt' AND post_status='publish' AND b.language_code = '" . esc_sql( $lang_code ) . "'
|
717 |
+
GROUP BY p.ID";
|
718 |
|
719 |
$ids = $wpdb->get_results( $sql );
|
720 |
if( !empty($ids) )
|
724 |
return false;
|
725 |
}
|
726 |
|
727 |
+
/**
|
728 |
+
* Popup button
|
729 |
+
* @param [type] $atts [description]
|
730 |
+
* @param [type] $content [description]
|
731 |
+
* @return [type] [description]
|
732 |
+
*/
|
733 |
+
public function popup_link_shortcode($atts, $content ) {
|
734 |
+
return '<a href="#" class="spu-open-'.$atts['popup'].'">'.do_shortcode( $content ).'</a>';
|
735 |
+
}
|
736 |
+
|
737 |
}
|
public/includes/class-spu-rules.php
CHANGED
@@ -14,7 +14,7 @@ class Spu_Rules
|
|
14 |
* @var int
|
15 |
*/
|
16 |
protected $post_id;
|
17 |
-
|
18 |
/**
|
19 |
* referrer using in ajax calls
|
20 |
* @var string
|
@@ -43,11 +43,11 @@ class Spu_Rules
|
|
43 |
* __construct
|
44 |
* Add all the filters to use later
|
45 |
*/
|
46 |
-
|
47 |
function __construct()
|
48 |
{
|
49 |
global $post;
|
50 |
-
|
51 |
// User
|
52 |
add_filter('spu/rules/rule_match/user_type', array($this, 'rule_match_user_type'), 10, 2);
|
53 |
add_filter('spu/rules/rule_match/logged_user', array($this, 'rule_match_logged_user'), 10, 2);
|
@@ -63,7 +63,7 @@ class Spu_Rules
|
|
63 |
add_filter('spu/rules/rule_match/post_format', array($this, 'rule_match_post_format'), 10, 2);
|
64 |
add_filter('spu/rules/rule_match/post_status', array($this, 'rule_match_post_status'), 10, 2);
|
65 |
add_filter('spu/rules/rule_match/taxonomy', array($this, 'rule_match_taxonomy'), 10, 2);
|
66 |
-
|
67 |
// Page
|
68 |
add_filter('spu/rules/rule_match/page', array($this, 'rule_match_post'), 10, 2);
|
69 |
add_filter('spu/rules/rule_match/page_type', array($this, 'rule_match_page_type'), 10, 2);
|
@@ -79,7 +79,7 @@ class Spu_Rules
|
|
79 |
add_filter('spu/rules/rule_match/query_string', array($this, 'rule_match_query_string'), 10, 2);
|
80 |
|
81 |
$this->post_id = isset( $post->ID ) ? $post->ID : '';
|
82 |
-
$this->referrer = isset($_SERVER['
|
83 |
$this->query_string = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '';
|
84 |
|
85 |
if( defined('DOING_AJAX') ) {
|
@@ -103,37 +103,37 @@ class Spu_Rules
|
|
103 |
$this->is_search = true;
|
104 |
}
|
105 |
}
|
106 |
-
|
107 |
}
|
108 |
-
|
109 |
-
|
110 |
/*
|
111 |
* check_rules
|
112 |
*
|
113 |
* @since 1.0.0
|
114 |
*/
|
115 |
-
|
116 |
function check_rules( $rules = '' )
|
117 |
{
|
118 |
-
|
119 |
//if no rules, add the box
|
120 |
$add_box = true;
|
121 |
|
122 |
if( !empty( $rules ) ) {
|
123 |
// vars
|
124 |
$add_box = false;
|
125 |
-
|
126 |
|
127 |
foreach( $rules as $group_id => $group ) {
|
128 |
// start of as true, this way, any rule that doesn't match will cause this varaible to false
|
129 |
$match_group = true;
|
130 |
-
|
131 |
if( is_array($group) )
|
132 |
{
|
133 |
|
134 |
foreach( $group as $rule_id => $rule )
|
135 |
-
{
|
136 |
-
|
137 |
// $match = true / false
|
138 |
$match = apply_filters( 'spu/rules/rule_match/' . $rule['param'] , false, $rule );
|
139 |
|
@@ -141,26 +141,26 @@ class Spu_Rules
|
|
141 |
{
|
142 |
$match_group = false;
|
143 |
}
|
144 |
-
|
145 |
}
|
146 |
}
|
147 |
-
|
148 |
-
|
149 |
// all rules must havematched!
|
150 |
if( $match_group )
|
151 |
{
|
152 |
$add_box = true;
|
153 |
}
|
154 |
-
|
155 |
}
|
156 |
-
|
157 |
-
|
158 |
}
|
159 |
-
|
160 |
-
|
161 |
return $add_box;
|
162 |
}
|
163 |
-
|
164 |
/**
|
165 |
* [rule_match_logged_user description]
|
166 |
* @param bool $match false default
|
@@ -170,16 +170,16 @@ class Spu_Rules
|
|
170 |
function rule_match_logged_user( $match, $rule ) {
|
171 |
|
172 |
if ( $rule['operator'] == "==" ) {
|
173 |
-
|
174 |
return is_user_logged_in();
|
175 |
|
176 |
} else {
|
177 |
|
178 |
return !is_user_logged_in();
|
179 |
|
180 |
-
}
|
181 |
|
182 |
-
}
|
183 |
|
184 |
/**
|
185 |
* [rule_match_mobiles description]
|
@@ -192,14 +192,14 @@ class Spu_Rules
|
|
192 |
$detect = new Mobile_Detect;
|
193 |
|
194 |
if ( $rule['operator'] == "==" ) {
|
195 |
-
|
196 |
return $detect->isMobile();
|
197 |
|
198 |
} else {
|
199 |
|
200 |
return !$detect->isMobile();
|
201 |
|
202 |
-
}
|
203 |
|
204 |
}
|
205 |
/**
|
@@ -213,14 +213,14 @@ class Spu_Rules
|
|
213 |
$detect = new Mobile_Detect;
|
214 |
|
215 |
if ( $rule['operator'] == "==" ) {
|
216 |
-
|
217 |
return $detect->isTablet();
|
218 |
|
219 |
} else {
|
220 |
|
221 |
return !$detect->isTablet();
|
222 |
|
223 |
-
}
|
224 |
|
225 |
}
|
226 |
/**
|
@@ -244,7 +244,7 @@ class Spu_Rules
|
|
244 |
}
|
245 |
|
246 |
}
|
247 |
-
|
248 |
/**
|
249 |
* [rule_match_left_comment description]
|
250 |
* @param bool $match false default
|
@@ -254,16 +254,16 @@ class Spu_Rules
|
|
254 |
function rule_match_left_comment( $match, $rule ) {
|
255 |
|
256 |
if ( $rule['operator'] == "==" ) {
|
257 |
-
|
258 |
-
return !empty( $_COOKIE['comment_author_'.COOKIEHASH] );
|
259 |
-
|
260 |
} else {
|
261 |
|
262 |
return empty( $_COOKIE['comment_author_'.COOKIEHASH] );
|
263 |
|
264 |
-
}
|
265 |
|
266 |
-
}
|
267 |
/**
|
268 |
* [rule_match_search_engine description]
|
269 |
* @param bool $match false default
|
@@ -278,9 +278,9 @@ class Spu_Rules
|
|
278 |
|
279 |
foreach ($SE as $url) {
|
280 |
if ( strpos( $ref,$url ) !==false ){
|
281 |
-
|
282 |
return $rule['operator'] == "==" ? true : false;
|
283 |
-
}
|
284 |
}
|
285 |
|
286 |
return $rule['operator'] == "==" ? false : true;
|
@@ -337,7 +337,7 @@ class Spu_Rules
|
|
337 |
|
338 |
parse_str( str_replace('?', '', $this->query_string ), $request );
|
339 |
parse_str( $rule['value'], $rule_query );
|
340 |
-
|
341 |
if( is_array( $request ) && is_array( $rule_query ) ) {
|
342 |
sort( $request );
|
343 |
sort( $rule_query );
|
@@ -366,11 +366,15 @@ class Spu_Rules
|
|
366 |
*/
|
367 |
function rule_match_same_site( $match, $rule ) {
|
368 |
|
369 |
-
|
370 |
$ref = $this->referrer;
|
371 |
|
372 |
$internal = str_replace( array( 'http://','https://' ), '', site_url() );
|
373 |
-
|
|
|
|
|
|
|
|
|
374 |
|
375 |
if( $rule['operator'] == "==" ) {
|
376 |
|
@@ -380,7 +384,7 @@ class Spu_Rules
|
|
380 |
|
381 |
return preg_match( '~' . $internal . '~i', $ref );
|
382 |
|
383 |
-
}
|
384 |
|
385 |
}
|
386 |
|
@@ -389,10 +393,10 @@ class Spu_Rules
|
|
389 |
*
|
390 |
* @since 1.0.0
|
391 |
*/
|
392 |
-
|
393 |
function rule_match_post_type( $match, $rule )
|
394 |
{
|
395 |
-
|
396 |
|
397 |
$post_type = $this->get_post_type();
|
398 |
|
@@ -405,23 +409,23 @@ class Spu_Rules
|
|
405 |
{
|
406 |
$match = ( $post_type !== $rule['value'] );
|
407 |
}
|
408 |
-
|
409 |
-
|
410 |
return $match;
|
411 |
}
|
412 |
-
|
413 |
-
|
414 |
/*
|
415 |
* rule_match_post
|
416 |
*
|
417 |
* @since 1.0.0
|
418 |
*/
|
419 |
-
|
420 |
function rule_match_post( $match, $rule )
|
421 |
{
|
422 |
-
|
423 |
$post_id = $this->post_id;
|
424 |
-
|
425 |
if($rule['operator'] == "==")
|
426 |
{
|
427 |
$match = ( $post_id == $rule['value'] );
|
@@ -430,77 +434,77 @@ class Spu_Rules
|
|
430 |
{
|
431 |
$match = ( $post_id != $rule['value'] );
|
432 |
}
|
433 |
-
|
434 |
return $match;
|
435 |
|
436 |
}
|
437 |
-
|
438 |
-
|
439 |
/*
|
440 |
* rule_match_page_type
|
441 |
*
|
442 |
* @since 1.0.0
|
443 |
*/
|
444 |
-
|
445 |
function rule_match_page_type( $match, $rule )
|
446 |
{
|
447 |
-
|
448 |
|
449 |
$post_id = $this->post_id;
|
450 |
|
451 |
$post = get_post( $post_id );
|
452 |
|
453 |
-
$post_parent = isset( $post->post_parent ) ? $post->post_parent : '';
|
454 |
-
|
455 |
$post_type = $this->get_post_type();
|
456 |
-
|
457 |
if( $rule['value'] == 'front_page') {
|
458 |
-
|
459 |
$front_page = (int) get_option('page_on_front');
|
460 |
|
461 |
if( $front_page !== 0 ) {
|
462 |
|
463 |
if($rule['operator'] == "==") {
|
464 |
-
|
465 |
$match = ( $front_page == $post_id );
|
466 |
-
|
467 |
} elseif($rule['operator'] == "!=") {
|
468 |
-
|
469 |
$match = ( $front_page != $post_id );
|
470 |
-
|
471 |
}
|
472 |
} else {
|
473 |
// if doing ajax is_home won't work so we do a workaround
|
474 |
if( defined( 'DOING_AJAX') ) {
|
475 |
-
|
476 |
-
$front_page = get_option( 'show_on_front' );
|
477 |
-
|
478 |
if($rule['operator'] == "==") {
|
479 |
-
|
480 |
$match = ( 'posts' == $front_page && $post_id == 0 );
|
481 |
-
|
482 |
} elseif($rule['operator'] == "!=") {
|
483 |
-
|
484 |
$match = !( 'posts' == $front_page && $post_id == 0 );
|
485 |
-
|
486 |
}
|
487 |
-
|
488 |
|
489 |
} else {
|
490 |
-
|
491 |
if($rule['operator'] == "==") {
|
492 |
-
|
493 |
$match = is_home();
|
494 |
-
|
495 |
} elseif($rule['operator'] == "!=") {
|
496 |
-
|
497 |
$match = !is_home();
|
498 |
-
|
499 |
}
|
500 |
}
|
501 |
|
502 |
}
|
503 |
-
|
504 |
}
|
505 |
elseif( $rule['value'] == 'category_page') {
|
506 |
|
@@ -573,58 +577,58 @@ class Spu_Rules
|
|
573 |
}
|
574 |
}
|
575 |
elseif( $rule['value'] == 'posts_page') {
|
576 |
-
|
577 |
$posts_page = (int) get_option('page_for_posts');
|
578 |
|
579 |
if( $posts_page !== 0 ) {
|
580 |
if($rule['operator'] == "==") {
|
581 |
-
|
582 |
$match = ( $posts_page == $post_id );
|
583 |
-
|
584 |
} elseif($rule['operator'] == "!=") {
|
585 |
-
|
586 |
$match = ( $posts_page != $post_id );
|
587 |
-
|
588 |
}
|
589 |
-
} else {
|
590 |
// if doing ajax is_home won't work so we do a workaround
|
591 |
if( defined( 'DOING_AJAX') ) {
|
592 |
-
|
593 |
-
|
594 |
if($rule['operator'] == "==") {
|
595 |
-
|
596 |
$match = ( 0 === $posts_page && $post_id == 0 );
|
597 |
-
|
598 |
} elseif($rule['operator'] == "!=") {
|
599 |
-
|
600 |
$match = !( 0 === $posts_page && $post_id == 0 );
|
601 |
-
|
602 |
}
|
603 |
-
|
604 |
|
605 |
} else {
|
606 |
if($rule['operator'] == "==") {
|
607 |
-
|
608 |
$match = is_home();
|
609 |
-
|
610 |
} elseif($rule['operator'] == "!=") {
|
611 |
-
|
612 |
$match = !is_home();
|
613 |
-
|
614 |
}
|
615 |
-
}
|
616 |
}
|
617 |
-
|
618 |
}
|
619 |
elseif( $rule['value'] == 'top_level') {
|
620 |
-
|
621 |
-
|
622 |
if( $options['page_parent'] )
|
623 |
{
|
624 |
$post_parent = $options['page_parent'];
|
625 |
}
|
626 |
-
|
627 |
-
|
628 |
if($rule['operator'] == "==")
|
629 |
{
|
630 |
$match = ( $post_parent == 0 );
|
@@ -633,16 +637,16 @@ class Spu_Rules
|
|
633 |
{
|
634 |
$match = ( $post_parent != 0 );
|
635 |
}
|
636 |
-
|
637 |
}
|
638 |
elseif( $rule['value'] == 'parent') {
|
639 |
-
|
640 |
$children = get_pages(array(
|
641 |
'post_type' => $post_type,
|
642 |
'child_of' => $post_id,
|
643 |
));
|
644 |
-
|
645 |
-
|
646 |
if($rule['operator'] == "==") {
|
647 |
$match = ( count($children) > 0 );
|
648 |
}
|
@@ -650,17 +654,17 @@ class Spu_Rules
|
|
650 |
{
|
651 |
$match = ( count($children) == 0 );
|
652 |
}
|
653 |
-
|
654 |
}
|
655 |
elseif( $rule['value'] == 'child') {
|
656 |
-
|
657 |
$post_parent = $post_parent;
|
658 |
if( $options['page_parent'] )
|
659 |
{
|
660 |
$post_parent = $options['page_parent'];
|
661 |
}
|
662 |
-
|
663 |
-
|
664 |
if($rule['operator'] == "==")
|
665 |
{
|
666 |
$match = ( $post_parent != 0 );
|
@@ -669,44 +673,44 @@ class Spu_Rules
|
|
669 |
{
|
670 |
$match = ( $post_parent == 0 );
|
671 |
}
|
672 |
-
|
673 |
} elseif( $rule['value'] == 'all_pages') {
|
674 |
-
|
675 |
$match = true;
|
676 |
-
|
677 |
}
|
678 |
-
|
679 |
return $match;
|
680 |
|
681 |
}
|
682 |
-
|
683 |
-
|
684 |
/*
|
685 |
* rule_match_page_parent
|
686 |
*
|
687 |
* @since 1.0.0
|
688 |
*/
|
689 |
-
|
690 |
function rule_match_page_parent( $match, $rule )
|
691 |
{
|
692 |
-
|
693 |
// validation
|
694 |
if( !$this->post_id )
|
695 |
{
|
696 |
return false;
|
697 |
}
|
698 |
-
|
699 |
-
|
700 |
// vars
|
701 |
$post = get_post( $this->post_id );
|
702 |
-
|
703 |
$post_parent = $post->post_parent;
|
704 |
if( $options['page_parent'] )
|
705 |
{
|
706 |
$post_parent = $options['page_parent'];
|
707 |
}
|
708 |
-
|
709 |
-
|
710 |
if($rule['operator'] == "==")
|
711 |
{
|
712 |
$match = ( $post_parent == $rule['value'] );
|
@@ -715,36 +719,36 @@ class Spu_Rules
|
|
715 |
{
|
716 |
$match = ( $post_parent != $rule['value'] );
|
717 |
}
|
718 |
-
|
719 |
-
|
720 |
return $match;
|
721 |
|
722 |
}
|
723 |
-
|
724 |
-
|
725 |
/*
|
726 |
* rule_match_page_template
|
727 |
*
|
728 |
* @since 1.0.0
|
729 |
*/
|
730 |
-
|
731 |
function rule_match_page_template( $match, $rule )
|
732 |
{
|
733 |
-
|
734 |
|
735 |
$page_template = get_post_meta( $this->post_id, '_wp_page_template', true );
|
736 |
|
737 |
-
|
738 |
if( ! $page_template ) {
|
739 |
-
|
740 |
if( 'page' == get_post_type( $this->post_id ) ) {
|
741 |
|
742 |
$page_template = "default";
|
743 |
|
744 |
}
|
745 |
}
|
746 |
-
|
747 |
-
|
748 |
if($rule['operator'] == "==")
|
749 |
{
|
750 |
$match = ( $page_template === $rule['value'] );
|
@@ -753,21 +757,21 @@ class Spu_Rules
|
|
753 |
{
|
754 |
$match = ( $page_template !== $rule['value'] );
|
755 |
}
|
756 |
-
|
757 |
return $match;
|
758 |
|
759 |
}
|
760 |
-
|
761 |
-
|
762 |
/*
|
763 |
* rule_match_post_category
|
764 |
*
|
765 |
* @since 1.0.0
|
766 |
*/
|
767 |
-
|
768 |
function rule_match_post_category( $match, $rule )
|
769 |
{
|
770 |
-
|
771 |
|
772 |
// validate
|
773 |
if( !$this->post_id )
|
@@ -775,10 +779,10 @@ class Spu_Rules
|
|
775 |
return false;
|
776 |
}
|
777 |
|
778 |
-
|
779 |
// post type
|
780 |
$post_type = $this->get_post_type();
|
781 |
-
|
782 |
// vars
|
783 |
$taxonomies = get_object_taxonomies( $post_type );
|
784 |
|
@@ -791,7 +795,7 @@ class Spu_Rules
|
|
791 |
}
|
792 |
}
|
793 |
|
794 |
-
// no terms at all?
|
795 |
if( empty($terms) )
|
796 |
{
|
797 |
// If no ters, this is a new post and should be treated as if it has the "Uncategorized" (1) category ticked
|
@@ -800,62 +804,62 @@ class Spu_Rules
|
|
800 |
$terms[] = '1';
|
801 |
}
|
802 |
}
|
803 |
-
|
804 |
|
805 |
if($rule['operator'] == "==")
|
806 |
{
|
807 |
$match = false;
|
808 |
-
|
809 |
if(!empty($terms))
|
810 |
{
|
811 |
if( in_array($rule['value'], $terms) )
|
812 |
{
|
813 |
-
$match = true;
|
814 |
}
|
815 |
}
|
816 |
-
|
817 |
}
|
818 |
elseif($rule['operator'] == "!=")
|
819 |
{
|
820 |
$match = true;
|
821 |
-
|
822 |
if($terms)
|
823 |
{
|
824 |
if( in_array($rule['value'], $terms) )
|
825 |
{
|
826 |
-
$match = false;
|
827 |
}
|
828 |
}
|
829 |
|
830 |
}
|
831 |
-
|
832 |
-
|
833 |
return $match;
|
834 |
-
|
835 |
}
|
836 |
-
|
837 |
-
|
838 |
/*
|
839 |
* rule_match_user_type
|
840 |
*
|
841 |
* @since 1.0.0
|
842 |
*/
|
843 |
-
|
844 |
function rule_match_user_type( $match, $rule )
|
845 |
{
|
846 |
$user = wp_get_current_user();
|
847 |
-
|
848 |
if( $rule['operator'] == "==" )
|
849 |
{
|
850 |
if( $rule['value'] == 'super_admin' )
|
851 |
{
|
852 |
$match = is_super_admin( $user->ID );
|
853 |
}
|
854 |
-
else
|
855 |
{
|
856 |
$match = in_array( $rule['value'], $user->roles );
|
857 |
}
|
858 |
-
|
859 |
}
|
860 |
elseif( $rule['operator'] == "!=" )
|
861 |
{
|
@@ -863,136 +867,136 @@ class Spu_Rules
|
|
863 |
{
|
864 |
$match = !is_super_admin( $user->ID );
|
865 |
}
|
866 |
-
else
|
867 |
{
|
868 |
$match = ( ! in_array( $rule['value'], $user->roles ) );
|
869 |
}
|
870 |
}
|
871 |
-
|
872 |
return $match;
|
873 |
-
|
874 |
}
|
875 |
-
|
876 |
-
|
877 |
-
|
878 |
-
|
879 |
/*
|
880 |
* rule_match_post_format
|
881 |
*
|
882 |
* @since 1.0.0
|
883 |
*/
|
884 |
-
|
885 |
function rule_match_post_format( $match, $rule )
|
886 |
{
|
887 |
-
|
888 |
-
|
889 |
// validate
|
890 |
if( !$this->post_id )
|
891 |
{
|
892 |
return false;
|
893 |
}
|
894 |
-
|
895 |
$post_type = $this->get_post_type();
|
896 |
-
|
897 |
-
|
898 |
// does post_type support 'post-format'
|
899 |
if( post_type_supports( $post_type, 'post-formats' ) )
|
900 |
{
|
901 |
$post_format = get_post_format( $this->post_id );
|
902 |
-
|
903 |
if( $post_format === false )
|
904 |
{
|
905 |
$post_format = 'standard';
|
906 |
}
|
907 |
}
|
908 |
-
|
909 |
|
910 |
-
|
|
|
911 |
if($rule['operator'] == "==")
|
912 |
{
|
913 |
$match = ( $post_format === $rule['value'] );
|
914 |
-
|
915 |
}
|
916 |
elseif($rule['operator'] == "!=")
|
917 |
{
|
918 |
$match = ( $post_format !== $rule['value'] );
|
919 |
}
|
920 |
-
|
921 |
-
|
922 |
-
|
923 |
return $match;
|
924 |
-
|
925 |
}
|
926 |
-
|
927 |
-
|
928 |
/*
|
929 |
* rule_match_post_status
|
930 |
*
|
931 |
* @since 1.0.0
|
932 |
*/
|
933 |
-
|
934 |
function rule_match_post_status( $match, $rule )
|
935 |
{
|
936 |
-
|
937 |
|
938 |
// validate
|
939 |
if( !$this->post_id )
|
940 |
{
|
941 |
return false;
|
942 |
}
|
943 |
-
|
944 |
-
|
945 |
// vars
|
946 |
$post_status = get_post_status( $this->post_id );
|
947 |
-
|
948 |
-
|
949 |
// auto-draft = draft
|
950 |
if( $post_status == 'auto-draft' )
|
951 |
{
|
952 |
$post_status = 'draft';
|
953 |
}
|
954 |
-
|
955 |
-
|
956 |
// match
|
957 |
if($rule['operator'] == "==")
|
958 |
{
|
959 |
$match = ( $post_status === $rule['value'] );
|
960 |
-
|
961 |
}
|
962 |
elseif($rule['operator'] == "!=")
|
963 |
{
|
964 |
$match = ( $post_status !== $rule['value'] );
|
965 |
}
|
966 |
-
|
967 |
-
|
968 |
// return
|
969 |
return $match;
|
970 |
-
|
971 |
}
|
972 |
-
|
973 |
-
|
974 |
/*
|
975 |
* rule_match_taxonomy
|
976 |
*
|
977 |
* @since 1.0.0
|
978 |
*/
|
979 |
-
|
980 |
function rule_match_taxonomy( $match, $rule )
|
981 |
{
|
982 |
-
|
983 |
// validate
|
984 |
if( !$this->post_id )
|
985 |
{
|
986 |
return false;
|
987 |
}
|
988 |
-
|
989 |
-
|
990 |
// post type
|
991 |
$post_type = $this->get_post_type();
|
992 |
-
|
993 |
// vars
|
994 |
$taxonomies = get_object_taxonomies( $post_type );
|
995 |
-
|
996 |
if( is_array($taxonomies) )
|
997 |
{
|
998 |
foreach( $taxonomies as $tax )
|
@@ -1007,8 +1011,8 @@ class Spu_Rules
|
|
1007 |
}
|
1008 |
}
|
1009 |
}
|
1010 |
-
|
1011 |
-
// no terms at all?
|
1012 |
if( empty($terms) )
|
1013 |
{
|
1014 |
// If no ters, this is a new post and should be treated as if it has the "Uncategorized" (1) category ticked
|
@@ -1017,46 +1021,46 @@ class Spu_Rules
|
|
1017 |
$terms[] = '1';
|
1018 |
}
|
1019 |
}
|
1020 |
-
|
1021 |
|
1022 |
-
|
|
|
1023 |
if($rule['operator'] == "==")
|
1024 |
{
|
1025 |
$match = false;
|
1026 |
-
|
1027 |
if($terms)
|
1028 |
{
|
1029 |
if( in_array($rule['value'], $terms) )
|
1030 |
{
|
1031 |
-
$match = true;
|
1032 |
}
|
1033 |
}
|
1034 |
-
|
1035 |
}
|
1036 |
elseif($rule['operator'] == "!=")
|
1037 |
{
|
1038 |
$match = true;
|
1039 |
-
|
1040 |
if($terms)
|
1041 |
{
|
1042 |
if( in_array($rule['value'], $terms) )
|
1043 |
{
|
1044 |
-
$match = false;
|
1045 |
}
|
1046 |
}
|
1047 |
|
1048 |
}
|
1049 |
-
|
1050 |
-
|
1051 |
return $match;
|
1052 |
-
|
1053 |
}
|
1054 |
-
|
1055 |
/**
|
1056 |
* Helper function to get post type
|
1057 |
* @since 1.2.3
|
1058 |
* @return string
|
1059 |
-
*
|
1060 |
*/
|
1061 |
function get_post_type(){
|
1062 |
global $wp_query;
|
@@ -1067,5 +1071,5 @@ class Spu_Rules
|
|
1067 |
|
1068 |
return $post_type;
|
1069 |
}
|
1070 |
-
|
1071 |
-
}
|
14 |
* @var int
|
15 |
*/
|
16 |
protected $post_id;
|
17 |
+
|
18 |
/**
|
19 |
* referrer using in ajax calls
|
20 |
* @var string
|
43 |
* __construct
|
44 |
* Add all the filters to use later
|
45 |
*/
|
46 |
+
|
47 |
function __construct()
|
48 |
{
|
49 |
global $post;
|
50 |
+
|
51 |
// User
|
52 |
add_filter('spu/rules/rule_match/user_type', array($this, 'rule_match_user_type'), 10, 2);
|
53 |
add_filter('spu/rules/rule_match/logged_user', array($this, 'rule_match_logged_user'), 10, 2);
|
63 |
add_filter('spu/rules/rule_match/post_format', array($this, 'rule_match_post_format'), 10, 2);
|
64 |
add_filter('spu/rules/rule_match/post_status', array($this, 'rule_match_post_status'), 10, 2);
|
65 |
add_filter('spu/rules/rule_match/taxonomy', array($this, 'rule_match_taxonomy'), 10, 2);
|
66 |
+
|
67 |
// Page
|
68 |
add_filter('spu/rules/rule_match/page', array($this, 'rule_match_post'), 10, 2);
|
69 |
add_filter('spu/rules/rule_match/page_type', array($this, 'rule_match_page_type'), 10, 2);
|
79 |
add_filter('spu/rules/rule_match/query_string', array($this, 'rule_match_query_string'), 10, 2);
|
80 |
|
81 |
$this->post_id = isset( $post->ID ) ? $post->ID : '';
|
82 |
+
$this->referrer = isset($_SERVER['HTTP_REFERER']) ? $_SERVER['HTTP_REFERER'] : '';
|
83 |
$this->query_string = isset($_SERVER['QUERY_STRING']) ? $_SERVER['QUERY_STRING'] : '';
|
84 |
|
85 |
if( defined('DOING_AJAX') ) {
|
103 |
$this->is_search = true;
|
104 |
}
|
105 |
}
|
106 |
+
|
107 |
}
|
108 |
+
|
109 |
+
|
110 |
/*
|
111 |
* check_rules
|
112 |
*
|
113 |
* @since 1.0.0
|
114 |
*/
|
115 |
+
|
116 |
function check_rules( $rules = '' )
|
117 |
{
|
118 |
+
|
119 |
//if no rules, add the box
|
120 |
$add_box = true;
|
121 |
|
122 |
if( !empty( $rules ) ) {
|
123 |
// vars
|
124 |
$add_box = false;
|
125 |
+
|
126 |
|
127 |
foreach( $rules as $group_id => $group ) {
|
128 |
// start of as true, this way, any rule that doesn't match will cause this varaible to false
|
129 |
$match_group = true;
|
130 |
+
|
131 |
if( is_array($group) )
|
132 |
{
|
133 |
|
134 |
foreach( $group as $rule_id => $rule )
|
135 |
+
{
|
136 |
+
|
137 |
// $match = true / false
|
138 |
$match = apply_filters( 'spu/rules/rule_match/' . $rule['param'] , false, $rule );
|
139 |
|
141 |
{
|
142 |
$match_group = false;
|
143 |
}
|
144 |
+
|
145 |
}
|
146 |
}
|
147 |
+
|
148 |
+
|
149 |
// all rules must havematched!
|
150 |
if( $match_group )
|
151 |
{
|
152 |
$add_box = true;
|
153 |
}
|
154 |
+
|
155 |
}
|
156 |
+
|
157 |
+
|
158 |
}
|
159 |
+
|
160 |
+
|
161 |
return $add_box;
|
162 |
}
|
163 |
+
|
164 |
/**
|
165 |
* [rule_match_logged_user description]
|
166 |
* @param bool $match false default
|
170 |
function rule_match_logged_user( $match, $rule ) {
|
171 |
|
172 |
if ( $rule['operator'] == "==" ) {
|
173 |
+
|
174 |
return is_user_logged_in();
|
175 |
|
176 |
} else {
|
177 |
|
178 |
return !is_user_logged_in();
|
179 |
|
180 |
+
}
|
181 |
|
182 |
+
}
|
183 |
|
184 |
/**
|
185 |
* [rule_match_mobiles description]
|
192 |
$detect = new Mobile_Detect;
|
193 |
|
194 |
if ( $rule['operator'] == "==" ) {
|
195 |
+
|
196 |
return $detect->isMobile();
|
197 |
|
198 |
} else {
|
199 |
|
200 |
return !$detect->isMobile();
|
201 |
|
202 |
+
}
|
203 |
|
204 |
}
|
205 |
/**
|
213 |
$detect = new Mobile_Detect;
|
214 |
|
215 |
if ( $rule['operator'] == "==" ) {
|
216 |
+
|
217 |
return $detect->isTablet();
|
218 |
|
219 |
} else {
|
220 |
|
221 |
return !$detect->isTablet();
|
222 |
|
223 |
+
}
|
224 |
|
225 |
}
|
226 |
/**
|
244 |
}
|
245 |
|
246 |
}
|
247 |
+
|
248 |
/**
|
249 |
* [rule_match_left_comment description]
|
250 |
* @param bool $match false default
|
254 |
function rule_match_left_comment( $match, $rule ) {
|
255 |
|
256 |
if ( $rule['operator'] == "==" ) {
|
257 |
+
|
258 |
+
return !empty( $_COOKIE['comment_author_'.COOKIEHASH] );
|
259 |
+
|
260 |
} else {
|
261 |
|
262 |
return empty( $_COOKIE['comment_author_'.COOKIEHASH] );
|
263 |
|
264 |
+
}
|
265 |
|
266 |
+
}
|
267 |
/**
|
268 |
* [rule_match_search_engine description]
|
269 |
* @param bool $match false default
|
278 |
|
279 |
foreach ($SE as $url) {
|
280 |
if ( strpos( $ref,$url ) !==false ){
|
281 |
+
|
282 |
return $rule['operator'] == "==" ? true : false;
|
283 |
+
}
|
284 |
}
|
285 |
|
286 |
return $rule['operator'] == "==" ? false : true;
|
337 |
|
338 |
parse_str( str_replace('?', '', $this->query_string ), $request );
|
339 |
parse_str( $rule['value'], $rule_query );
|
340 |
+
|
341 |
if( is_array( $request ) && is_array( $rule_query ) ) {
|
342 |
sort( $request );
|
343 |
sort( $rule_query );
|
366 |
*/
|
367 |
function rule_match_same_site( $match, $rule ) {
|
368 |
|
369 |
+
|
370 |
$ref = $this->referrer;
|
371 |
|
372 |
$internal = str_replace( array( 'http://','https://' ), '', site_url() );
|
373 |
+
echo "<pre>";
|
374 |
+
var_dump($internal);
|
375 |
+
var_dump($ref);
|
376 |
+
var_dump(preg_match( '~' . $internal . '~i', $ref ));
|
377 |
+
echo "</pre>";
|
378 |
|
379 |
if( $rule['operator'] == "==" ) {
|
380 |
|
384 |
|
385 |
return preg_match( '~' . $internal . '~i', $ref );
|
386 |
|
387 |
+
}
|
388 |
|
389 |
}
|
390 |
|
393 |
*
|
394 |
* @since 1.0.0
|
395 |
*/
|
396 |
+
|
397 |
function rule_match_post_type( $match, $rule )
|
398 |
{
|
399 |
+
|
400 |
|
401 |
$post_type = $this->get_post_type();
|
402 |
|
409 |
{
|
410 |
$match = ( $post_type !== $rule['value'] );
|
411 |
}
|
412 |
+
|
413 |
+
|
414 |
return $match;
|
415 |
}
|
416 |
+
|
417 |
+
|
418 |
/*
|
419 |
* rule_match_post
|
420 |
*
|
421 |
* @since 1.0.0
|
422 |
*/
|
423 |
+
|
424 |
function rule_match_post( $match, $rule )
|
425 |
{
|
426 |
+
|
427 |
$post_id = $this->post_id;
|
428 |
+
|
429 |
if($rule['operator'] == "==")
|
430 |
{
|
431 |
$match = ( $post_id == $rule['value'] );
|
434 |
{
|
435 |
$match = ( $post_id != $rule['value'] );
|
436 |
}
|
437 |
+
|
438 |
return $match;
|
439 |
|
440 |
}
|
441 |
+
|
442 |
+
|
443 |
/*
|
444 |
* rule_match_page_type
|
445 |
*
|
446 |
* @since 1.0.0
|
447 |
*/
|
448 |
+
|
449 |
function rule_match_page_type( $match, $rule )
|
450 |
{
|
451 |
+
|
452 |
|
453 |
$post_id = $this->post_id;
|
454 |
|
455 |
$post = get_post( $post_id );
|
456 |
|
457 |
+
$post_parent = isset( $post->post_parent ) ? $post->post_parent : '';
|
458 |
+
|
459 |
$post_type = $this->get_post_type();
|
460 |
+
|
461 |
if( $rule['value'] == 'front_page') {
|
462 |
+
|
463 |
$front_page = (int) get_option('page_on_front');
|
464 |
|
465 |
if( $front_page !== 0 ) {
|
466 |
|
467 |
if($rule['operator'] == "==") {
|
468 |
+
|
469 |
$match = ( $front_page == $post_id );
|
470 |
+
|
471 |
} elseif($rule['operator'] == "!=") {
|
472 |
+
|
473 |
$match = ( $front_page != $post_id );
|
474 |
+
|
475 |
}
|
476 |
} else {
|
477 |
// if doing ajax is_home won't work so we do a workaround
|
478 |
if( defined( 'DOING_AJAX') ) {
|
479 |
+
|
480 |
+
$front_page = get_option( 'show_on_front' );
|
481 |
+
|
482 |
if($rule['operator'] == "==") {
|
483 |
+
|
484 |
$match = ( 'posts' == $front_page && $post_id == 0 );
|
485 |
+
|
486 |
} elseif($rule['operator'] == "!=") {
|
487 |
+
|
488 |
$match = !( 'posts' == $front_page && $post_id == 0 );
|
489 |
+
|
490 |
}
|
491 |
+
|
492 |
|
493 |
} else {
|
494 |
+
|
495 |
if($rule['operator'] == "==") {
|
496 |
+
|
497 |
$match = is_home();
|
498 |
+
|
499 |
} elseif($rule['operator'] == "!=") {
|
500 |
+
|
501 |
$match = !is_home();
|
502 |
+
|
503 |
}
|
504 |
}
|
505 |
|
506 |
}
|
507 |
+
|
508 |
}
|
509 |
elseif( $rule['value'] == 'category_page') {
|
510 |
|
577 |
}
|
578 |
}
|
579 |
elseif( $rule['value'] == 'posts_page') {
|
580 |
+
|
581 |
$posts_page = (int) get_option('page_for_posts');
|
582 |
|
583 |
if( $posts_page !== 0 ) {
|
584 |
if($rule['operator'] == "==") {
|
585 |
+
|
586 |
$match = ( $posts_page == $post_id );
|
587 |
+
|
588 |
} elseif($rule['operator'] == "!=") {
|
589 |
+
|
590 |
$match = ( $posts_page != $post_id );
|
591 |
+
|
592 |
}
|
593 |
+
} else {
|
594 |
// if doing ajax is_home won't work so we do a workaround
|
595 |
if( defined( 'DOING_AJAX') ) {
|
596 |
+
|
597 |
+
|
598 |
if($rule['operator'] == "==") {
|
599 |
+
|
600 |
$match = ( 0 === $posts_page && $post_id == 0 );
|
601 |
+
|
602 |
} elseif($rule['operator'] == "!=") {
|
603 |
+
|
604 |
$match = !( 0 === $posts_page && $post_id == 0 );
|
605 |
+
|
606 |
}
|
607 |
+
|
608 |
|
609 |
} else {
|
610 |
if($rule['operator'] == "==") {
|
611 |
+
|
612 |
$match = is_home();
|
613 |
+
|
614 |
} elseif($rule['operator'] == "!=") {
|
615 |
+
|
616 |
$match = !is_home();
|
617 |
+
|
618 |
}
|
619 |
+
}
|
620 |
}
|
621 |
+
|
622 |
}
|
623 |
elseif( $rule['value'] == 'top_level') {
|
624 |
+
|
625 |
+
|
626 |
if( $options['page_parent'] )
|
627 |
{
|
628 |
$post_parent = $options['page_parent'];
|
629 |
}
|
630 |
+
|
631 |
+
|
632 |
if($rule['operator'] == "==")
|
633 |
{
|
634 |
$match = ( $post_parent == 0 );
|
637 |
{
|
638 |
$match = ( $post_parent != 0 );
|
639 |
}
|
640 |
+
|
641 |
}
|
642 |
elseif( $rule['value'] == 'parent') {
|
643 |
+
|
644 |
$children = get_pages(array(
|
645 |
'post_type' => $post_type,
|
646 |
'child_of' => $post_id,
|
647 |
));
|
648 |
+
|
649 |
+
|
650 |
if($rule['operator'] == "==") {
|
651 |
$match = ( count($children) > 0 );
|
652 |
}
|
654 |
{
|
655 |
$match = ( count($children) == 0 );
|
656 |
}
|
657 |
+
|
658 |
}
|
659 |
elseif( $rule['value'] == 'child') {
|
660 |
+
|
661 |
$post_parent = $post_parent;
|
662 |
if( $options['page_parent'] )
|
663 |
{
|
664 |
$post_parent = $options['page_parent'];
|
665 |
}
|
666 |
+
|
667 |
+
|
668 |
if($rule['operator'] == "==")
|
669 |
{
|
670 |
$match = ( $post_parent != 0 );
|
673 |
{
|
674 |
$match = ( $post_parent == 0 );
|
675 |
}
|
676 |
+
|
677 |
} elseif( $rule['value'] == 'all_pages') {
|
678 |
+
|
679 |
$match = true;
|
680 |
+
|
681 |
}
|
682 |
+
|
683 |
return $match;
|
684 |
|
685 |
}
|
686 |
+
|
687 |
+
|
688 |
/*
|
689 |
* rule_match_page_parent
|
690 |
*
|
691 |
* @since 1.0.0
|
692 |
*/
|
693 |
+
|
694 |
function rule_match_page_parent( $match, $rule )
|
695 |
{
|
696 |
+
|
697 |
// validation
|
698 |
if( !$this->post_id )
|
699 |
{
|
700 |
return false;
|
701 |
}
|
702 |
+
|
703 |
+
|
704 |
// vars
|
705 |
$post = get_post( $this->post_id );
|
706 |
+
|
707 |
$post_parent = $post->post_parent;
|
708 |
if( $options['page_parent'] )
|
709 |
{
|
710 |
$post_parent = $options['page_parent'];
|
711 |
}
|
712 |
+
|
713 |
+
|
714 |
if($rule['operator'] == "==")
|
715 |
{
|
716 |
$match = ( $post_parent == $rule['value'] );
|
719 |
{
|
720 |
$match = ( $post_parent != $rule['value'] );
|
721 |
}
|
722 |
+
|
723 |
+
|
724 |
return $match;
|
725 |
|
726 |
}
|
727 |
+
|
728 |
+
|
729 |
/*
|
730 |
* rule_match_page_template
|
731 |
*
|
732 |
* @since 1.0.0
|
733 |
*/
|
734 |
+
|
735 |
function rule_match_page_template( $match, $rule )
|
736 |
{
|
737 |
+
|
738 |
|
739 |
$page_template = get_post_meta( $this->post_id, '_wp_page_template', true );
|
740 |
|
741 |
+
|
742 |
if( ! $page_template ) {
|
743 |
+
|
744 |
if( 'page' == get_post_type( $this->post_id ) ) {
|
745 |
|
746 |
$page_template = "default";
|
747 |
|
748 |
}
|
749 |
}
|
750 |
+
|
751 |
+
|
752 |
if($rule['operator'] == "==")
|
753 |
{
|
754 |
$match = ( $page_template === $rule['value'] );
|
757 |
{
|
758 |
$match = ( $page_template !== $rule['value'] );
|
759 |
}
|
760 |
+
|
761 |
return $match;
|
762 |
|
763 |
}
|
764 |
+
|
765 |
+
|
766 |
/*
|
767 |
* rule_match_post_category
|
768 |
*
|
769 |
* @since 1.0.0
|
770 |
*/
|
771 |
+
|
772 |
function rule_match_post_category( $match, $rule )
|
773 |
{
|
774 |
+
|
775 |
|
776 |
// validate
|
777 |
if( !$this->post_id )
|
779 |
return false;
|
780 |
}
|
781 |
|
782 |
+
|
783 |
// post type
|
784 |
$post_type = $this->get_post_type();
|
785 |
+
|
786 |
// vars
|
787 |
$taxonomies = get_object_taxonomies( $post_type );
|
788 |
|
795 |
}
|
796 |
}
|
797 |
|
798 |
+
// no terms at all?
|
799 |
if( empty($terms) )
|
800 |
{
|
801 |
// If no ters, this is a new post and should be treated as if it has the "Uncategorized" (1) category ticked
|
804 |
$terms[] = '1';
|
805 |
}
|
806 |
}
|
807 |
+
|
808 |
|
809 |
if($rule['operator'] == "==")
|
810 |
{
|
811 |
$match = false;
|
812 |
+
|
813 |
if(!empty($terms))
|
814 |
{
|
815 |
if( in_array($rule['value'], $terms) )
|
816 |
{
|
817 |
+
$match = true;
|
818 |
}
|
819 |
}
|
820 |
+
|
821 |
}
|
822 |
elseif($rule['operator'] == "!=")
|
823 |
{
|
824 |
$match = true;
|
825 |
+
|
826 |
if($terms)
|
827 |
{
|
828 |
if( in_array($rule['value'], $terms) )
|
829 |
{
|
830 |
+
$match = false;
|
831 |
}
|
832 |
}
|
833 |
|
834 |
}
|
835 |
+
|
836 |
+
|
837 |
return $match;
|
838 |
+
|
839 |
}
|
840 |
+
|
841 |
+
|
842 |
/*
|
843 |
* rule_match_user_type
|
844 |
*
|
845 |
* @since 1.0.0
|
846 |
*/
|
847 |
+
|
848 |
function rule_match_user_type( $match, $rule )
|
849 |
{
|
850 |
$user = wp_get_current_user();
|
851 |
+
|
852 |
if( $rule['operator'] == "==" )
|
853 |
{
|
854 |
if( $rule['value'] == 'super_admin' )
|
855 |
{
|
856 |
$match = is_super_admin( $user->ID );
|
857 |
}
|
858 |
+
else
|
859 |
{
|
860 |
$match = in_array( $rule['value'], $user->roles );
|
861 |
}
|
862 |
+
|
863 |
}
|
864 |
elseif( $rule['operator'] == "!=" )
|
865 |
{
|
867 |
{
|
868 |
$match = !is_super_admin( $user->ID );
|
869 |
}
|
870 |
+
else
|
871 |
{
|
872 |
$match = ( ! in_array( $rule['value'], $user->roles ) );
|
873 |
}
|
874 |
}
|
875 |
+
|
876 |
return $match;
|
877 |
+
|
878 |
}
|
879 |
+
|
880 |
+
|
881 |
+
|
882 |
+
|
883 |
/*
|
884 |
* rule_match_post_format
|
885 |
*
|
886 |
* @since 1.0.0
|
887 |
*/
|
888 |
+
|
889 |
function rule_match_post_format( $match, $rule )
|
890 |
{
|
891 |
+
|
892 |
+
|
893 |
// validate
|
894 |
if( !$this->post_id )
|
895 |
{
|
896 |
return false;
|
897 |
}
|
898 |
+
|
899 |
$post_type = $this->get_post_type();
|
900 |
+
|
901 |
+
|
902 |
// does post_type support 'post-format'
|
903 |
if( post_type_supports( $post_type, 'post-formats' ) )
|
904 |
{
|
905 |
$post_format = get_post_format( $this->post_id );
|
906 |
+
|
907 |
if( $post_format === false )
|
908 |
{
|
909 |
$post_format = 'standard';
|
910 |
}
|
911 |
}
|
|
|
912 |
|
913 |
+
|
914 |
+
|
915 |
if($rule['operator'] == "==")
|
916 |
{
|
917 |
$match = ( $post_format === $rule['value'] );
|
918 |
+
|
919 |
}
|
920 |
elseif($rule['operator'] == "!=")
|
921 |
{
|
922 |
$match = ( $post_format !== $rule['value'] );
|
923 |
}
|
924 |
+
|
925 |
+
|
926 |
+
|
927 |
return $match;
|
928 |
+
|
929 |
}
|
930 |
+
|
931 |
+
|
932 |
/*
|
933 |
* rule_match_post_status
|
934 |
*
|
935 |
* @since 1.0.0
|
936 |
*/
|
937 |
+
|
938 |
function rule_match_post_status( $match, $rule )
|
939 |
{
|
940 |
+
|
941 |
|
942 |
// validate
|
943 |
if( !$this->post_id )
|
944 |
{
|
945 |
return false;
|
946 |
}
|
947 |
+
|
948 |
+
|
949 |
// vars
|
950 |
$post_status = get_post_status( $this->post_id );
|
951 |
+
|
952 |
+
|
953 |
// auto-draft = draft
|
954 |
if( $post_status == 'auto-draft' )
|
955 |
{
|
956 |
$post_status = 'draft';
|
957 |
}
|
958 |
+
|
959 |
+
|
960 |
// match
|
961 |
if($rule['operator'] == "==")
|
962 |
{
|
963 |
$match = ( $post_status === $rule['value'] );
|
964 |
+
|
965 |
}
|
966 |
elseif($rule['operator'] == "!=")
|
967 |
{
|
968 |
$match = ( $post_status !== $rule['value'] );
|
969 |
}
|
970 |
+
|
971 |
+
|
972 |
// return
|
973 |
return $match;
|
974 |
+
|
975 |
}
|
976 |
+
|
977 |
+
|
978 |
/*
|
979 |
* rule_match_taxonomy
|
980 |
*
|
981 |
* @since 1.0.0
|
982 |
*/
|
983 |
+
|
984 |
function rule_match_taxonomy( $match, $rule )
|
985 |
{
|
986 |
+
|
987 |
// validate
|
988 |
if( !$this->post_id )
|
989 |
{
|
990 |
return false;
|
991 |
}
|
992 |
+
|
993 |
+
|
994 |
// post type
|
995 |
$post_type = $this->get_post_type();
|
996 |
+
|
997 |
// vars
|
998 |
$taxonomies = get_object_taxonomies( $post_type );
|
999 |
+
|
1000 |
if( is_array($taxonomies) )
|
1001 |
{
|
1002 |
foreach( $taxonomies as $tax )
|
1011 |
}
|
1012 |
}
|
1013 |
}
|
1014 |
+
|
1015 |
+
// no terms at all?
|
1016 |
if( empty($terms) )
|
1017 |
{
|
1018 |
// If no ters, this is a new post and should be treated as if it has the "Uncategorized" (1) category ticked
|
1021 |
$terms[] = '1';
|
1022 |
}
|
1023 |
}
|
|
|
1024 |
|
1025 |
+
|
1026 |
+
|
1027 |
if($rule['operator'] == "==")
|
1028 |
{
|
1029 |
$match = false;
|
1030 |
+
|
1031 |
if($terms)
|
1032 |
{
|
1033 |
if( in_array($rule['value'], $terms) )
|
1034 |
{
|
1035 |
+
$match = true;
|
1036 |
}
|
1037 |
}
|
1038 |
+
|
1039 |
}
|
1040 |
elseif($rule['operator'] == "!=")
|
1041 |
{
|
1042 |
$match = true;
|
1043 |
+
|
1044 |
if($terms)
|
1045 |
{
|
1046 |
if( in_array($rule['value'], $terms) )
|
1047 |
{
|
1048 |
+
$match = false;
|
1049 |
}
|
1050 |
}
|
1051 |
|
1052 |
}
|
1053 |
+
|
1054 |
+
|
1055 |
return $match;
|
1056 |
+
|
1057 |
}
|
1058 |
+
|
1059 |
/**
|
1060 |
* Helper function to get post type
|
1061 |
* @since 1.2.3
|
1062 |
* @return string
|
1063 |
+
*
|
1064 |
*/
|
1065 |
function get_post_type(){
|
1066 |
global $wp_query;
|
1071 |
|
1072 |
return $post_type;
|
1073 |
}
|
1074 |
+
|
1075 |
+
}
|