@@ -44,7 +44,7 @@ class Ad_Code_Manager
4444 public $ plugin_slug = 'ad-code-manager ' ;
4545 public $ manage_ads_cap = 'manage_options ' ;
4646 public $ post_type_labels ;
47- // public $logical_operator;
47+ public $ logical_operator ;
4848 public $ ad_tag_ids ;
4949 public $ providers ;
5050 public $ current_provider_slug ;
@@ -170,7 +170,7 @@ function action_init() {
170170 */
171171 $ this ->whitelisted_conditionals = apply_filters ( 'acm_whitelisted_conditionals ' , $ this ->whitelisted_conditionals );
172172 // Allow users to filter default logical operator
173- // $this->logical_operator = apply_filters( 'acm_logical_operator', 'OR' );
173+ $ this ->logical_operator = apply_filters ( 'acm_logical_operator ' , 'OR ' );
174174
175175 // Allow the ad management cap to be filtered if need be
176176 $ this ->manage_ads_cap = apply_filters ( 'acm_manage_ads_cap ' , $ this ->manage_ads_cap );
@@ -225,7 +225,7 @@ function handle_admin_action() {
225225 case 'edit ' :
226226 $ id = ( isset ( $ _REQUEST ['id ' ] ) ) ? (int )$ _REQUEST ['id ' ] : 0 ;
227227 $ priority = ( isset ( $ _REQUEST ['priority ' ] ) ) ? (int )$ _REQUEST ['priority ' ] : 10 ;
228- $ operator = ( isset ( $ _REQUEST ['operator ' ] ) && $ _REQUEST ['operator ' ] == 'AND ' ) ? ' AND ' : ' OR ' ;
228+ $ operator = ( isset ( $ _REQUEST ['operator ' ] ) && in_array ( $ _REQUEST ['operator ' ], array ( 'AND ' , ' OR ' ) ) ) ? $ _REQUEST [ ' operator ' ] : $ this -> logical_operator ;
229229 $ ad_code_vals = array (
230230 'priority ' => $ priority ,
231231 'operator ' => $ operator ,
@@ -337,7 +337,7 @@ function get_ad_codes( $query_args = array() ) {
337337 $ priority = ( !empty ( $ priority ) ) ? intval ( $ priority ) : 10 ;
338338
339339 $ operator = get_post_meta ( $ ad_code_cpt ->ID , 'operator ' , true );
340- $ operator = ( !empty ( $ operator ) ) ? esc_html ( $ operator ) : ' OR ' ;
340+ $ operator = ( !empty ( $ operator ) ) ? esc_html ( $ operator ) : $ this -> logical_operator ;
341341
342342 $ ad_codes_formatted [] = array (
343343 'conditionals ' => $ this ->get_conditionals ( $ ad_code_cpt ->ID ),
@@ -373,8 +373,7 @@ function get_ad_code( $post_id ) {
373373 $ priority = ( !empty ( $ priority ) ) ? intval ( $ priority ) : 10 ;
374374
375375 $ operator = get_post_meta ( $ post_id , 'operator ' , true );
376- $ operator = ( !empty ( $ operator ) ) ? esc_html ( $ operator ) : 'OR ' ;
377- $ operator = apply_filters ( 'acm_logical_operator ' , $ operator );
376+ $ operator = ( !empty ( $ operator ) ) ? esc_html ( $ operator ) : $ this ->logical_operator ;
378377
379378 $ ad_code_formatted = array (
380379 'conditionals ' => $ this ->get_conditionals ( $ post ->ID ),
@@ -703,7 +702,7 @@ function register_scripts_and_styles() {
703702 * @param int $priority Priority of the ad code in comparison to others
704703 * @return bool|WP_Error $success Whether we were successful in registering the ad tag
705704 */
706- function register_ad_code ( $ tag , $ url , $ conditionals = array (), $ url_vars = array (), $ priority = 10 , $ operator = ' OR ' ) {
705+ function register_ad_code ( $ tag , $ url , $ conditionals = array (), $ url_vars = array (), $ priority = 10 , $ operator = false ) {
707706
708707 // Run $url aganist a whitelist to make sure it's a safe URL
709708 if ( !$ this ->validate_script_url ( $ url ) )
@@ -719,7 +718,8 @@ function register_ad_code( $tag, $url, $conditionals = array(), $url_vars = arra
719718 $ priority = 10 ;
720719
721720 // Make sure our operator is 'OR' or 'AND'
722- $ operator = $ operator == 'AND ' ? 'AND ' : 'OR ' ;
721+ if ( ! $ operator || ! in_array ( $ operator , array ( 'AND ' , 'OR ' ) ) )
722+ $ operator = $ this ->logical_operator ;
723723
724724 // Save the ad code to our set of ad codes
725725 $ this ->ad_codes [$ tag ][] = array (
@@ -750,7 +750,7 @@ function register_ad_codes( $ad_codes = array() ) {
750750 'conditionals ' => array (),
751751 'url_vars ' => array (),
752752 'priority ' => 10 ,
753- 'operator ' => ' OR ' ,
753+ 'operator ' => $ this -> logical_operator ,
754754 );
755755 $ ad_code = array_merge ( $ default , $ ad_code );
756756
@@ -764,7 +764,8 @@ function register_ad_codes( $ad_codes = array() ) {
764764 $ ad_code ['priority ' ] = strlen ( $ ad_code ['priority ' ] ) == 0 ? 10 : intval ( $ ad_code ['priority ' ] ); //make sure priority is int, if it's unset, we set it to 10
765765
766766 // Make sure our operator is 'OR' or 'AND'
767- $ ad_code ['operator ' ] = $ ad_code ['operator ' ] == 'AND ' ? 'AND ' : 'OR ' ;
767+ if ( ! $ ad_code ['operator ' ] || ! in_array ( $ ad_code ['operator ' ], array ( 'AND ' , 'OR ' ) ) )
768+ $ operator = $ this ->logical_operator ;
768769
769770 $ this ->register_ad_code ( $ default_tag ['tag ' ], apply_filters ( 'acm_default_url ' , $ ad_code ['url ' ] ), $ ad_code ['conditionals ' ], array_merge ( $ default_tag ['url_vars ' ], $ ad_code ['url_vars ' ] ), $ ad_code ['priority ' ], $ ad_code ['operator ' ] );
770771 }
0 commit comments