abstracts
9 months ago
admin
10 months ago
ads
9 months ago
compatibility
9 months ago
crons
1 year ago
frontend
11 months ago
groups
1 year ago
importers
1 year ago
installation
1 year ago
interfaces
1 year ago
placements
1 year ago
rest
1 year ago
traits
1 year ago
utilities
11 months ago
array_ad_conditions.php
1 year ago
cap_map.php
3 years ago
class-assets-registry.php
1 year ago
class-autoloader.php
1 year ago
class-constants.php
1 year ago
class-entities.php
1 year ago
class-modal.php
1 year ago
class-modules.php
1 year ago
class-options.php
1 year ago
class-plugin.php
1 year ago
class-post-data.php
10 months ago
class-shortcodes.php
1 year ago
class-upgrades.php
1 year ago
class-widget.php
11 months ago
default-hooks.php
1 year ago
functions-ad.php
1 year ago
functions-conditional.php
1 year ago
functions-core.php
1 year ago
functions-group.php
1 year ago
functions-placement.php
1 year ago
functions.php
1 year ago
index.php
2 years ago
load_modules.php
2 years ago
functions-conditional.php
85 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Conditional functions. |
| 4 | * |
| 5 | * @package AdvancedAds |
| 6 | * @author Advanced Ads <info@wpadvancedads.com> |
| 7 | * @since 2.0.0 |
| 8 | */ |
| 9 | |
| 10 | use AdvancedAds\Framework\Utilities\Params; |
| 11 | |
| 12 | /** |
| 13 | * Return true if ads can be displayed |
| 14 | * |
| 15 | * @since 1.4.9 |
| 16 | * |
| 17 | * @return bool, true if ads can be displayed |
| 18 | */ |
| 19 | function advads_can_display_ads() { |
| 20 | return Advanced_Ads::get_instance()->can_display_ads(); |
| 21 | } |
| 22 | |
| 23 | /** |
| 24 | * Are we currently on an AMP URL? |
| 25 | * Will always return `false` and show PHP Notice if called before the `wp` hook. |
| 26 | * |
| 27 | * @return bool true if amp url, false otherwise |
| 28 | */ |
| 29 | function advads_is_amp() { |
| 30 | global $pagenow; |
| 31 | |
| 32 | if ( |
| 33 | is_admin() || |
| 34 | is_embed() || |
| 35 | is_feed() || |
| 36 | ( isset( $pagenow ) && in_array( $pagenow, [ 'wp-login.php', 'wp-signup.php', 'wp-activate.php' ], true ) ) || |
| 37 | ( defined( 'REST_REQUEST' ) && REST_REQUEST ) || |
| 38 | ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) |
| 39 | ) { |
| 40 | return false; |
| 41 | } |
| 42 | |
| 43 | if ( ! did_action( 'wp' ) ) { |
| 44 | return false; |
| 45 | } |
| 46 | |
| 47 | return ( function_exists( 'is_amp_endpoint' ) && \is_amp_endpoint() ) || |
| 48 | ( function_exists( 'is_wp_amp' ) && \is_wp_amp() ) || |
| 49 | ( function_exists( 'ampforwp_is_amp_endpoint' ) && \ampforwp_is_amp_endpoint() ) || |
| 50 | ( function_exists( 'is_penci_amp' ) && \is_penci_amp() ) || |
| 51 | Params::get( 'wpamp' ); |
| 52 | } |
| 53 | |
| 54 | /** |
| 55 | * Test if a placement has ads. |
| 56 | * |
| 57 | * @param int $id Id of the placement. |
| 58 | * |
| 59 | * @return bool |
| 60 | */ |
| 61 | function placement_has_ads( $id = '' ) { |
| 62 | $args = [ |
| 63 | 'global_output' => false, |
| 64 | 'cache-busting' => 'ignore', |
| 65 | ]; |
| 66 | |
| 67 | return get_the_placement( $id, '', $args ) !== ''; |
| 68 | } |
| 69 | |
| 70 | /** |
| 71 | * Test if a group has ads. |
| 72 | * |
| 73 | * @param int $id Id of the placement. |
| 74 | * |
| 75 | * @return bool |
| 76 | */ |
| 77 | function group_has_ads( $id = '' ) { |
| 78 | $args = [ |
| 79 | 'global_output' => false, |
| 80 | 'cache-busting' => 'ignore', |
| 81 | ]; |
| 82 | |
| 83 | return get_the_group( $id, '', $args ) !== ''; |
| 84 | } |
| 85 |