array_ad_conditions.php
8 years ago
cap_map.php
10 years ago
functions.php
6 years ago
load_modules.php
8 years ago
functions.php
145 lines
| 1 | <?php |
| 2 | |
| 3 | /* |
| 4 | * functions that are directly available in WordPress themes (and plugins) |
| 5 | */ |
| 6 | |
| 7 | /** |
| 8 | * return ad content |
| 9 | * |
| 10 | * @since 1.0.0 |
| 11 | * @param int $id id of the ad (post) |
| 12 | * @param arr $args additional arguments |
| 13 | */ |
| 14 | function get_ad($id = 0, $args = array()){ |
| 15 | if ( defined( 'ADVANCED_ADS_DISABLE_CHANGE' ) && ADVANCED_ADS_DISABLE_CHANGE ) { |
| 16 | $args = array(); |
| 17 | } |
| 18 | |
| 19 | return Advanced_Ads_Select::get_instance()->get_ad_by_method( $id, 'id', $args ); |
| 20 | } |
| 21 | |
| 22 | /** |
| 23 | * echo an ad |
| 24 | * |
| 25 | * @since 1.0.0 |
| 26 | * @param int $id id of the ad (post) |
| 27 | * @param arr $args additional arguments |
| 28 | */ |
| 29 | function the_ad($id = 0, $args = array()){ |
| 30 | echo get_ad( $id, $args ); |
| 31 | } |
| 32 | |
| 33 | /** |
| 34 | * return an ad from an ad group based on ad weight |
| 35 | * |
| 36 | * @since 1.0.0 |
| 37 | * @param int $id id of the ad group (taxonomy) |
| 38 | * |
| 39 | */ |
| 40 | function get_ad_group( $id = 0, $args = array() ) { |
| 41 | if ( defined( 'ADVANCED_ADS_DISABLE_CHANGE' ) && ADVANCED_ADS_DISABLE_CHANGE ) { |
| 42 | $args = array(); |
| 43 | } |
| 44 | return Advanced_Ads_Select::get_instance()->get_ad_by_method( $id, 'group', $args ); |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * echo an ad from an ad group |
| 49 | * |
| 50 | * @since 1.0.0 |
| 51 | * @param int $id id of the ad (post) |
| 52 | */ |
| 53 | function the_ad_group($id = 0){ |
| 54 | echo get_ad_group( $id ); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * return content of an ad placement |
| 59 | * |
| 60 | * @since 1.1.0 |
| 61 | * @param string $id slug of the ad placement |
| 62 | * |
| 63 | */ |
| 64 | function get_ad_placement( $id = '', $args = array() ) { |
| 65 | if ( defined( 'ADVANCED_ADS_DISABLE_CHANGE' ) && ADVANCED_ADS_DISABLE_CHANGE ) { |
| 66 | $args = array(); |
| 67 | } |
| 68 | return Advanced_Ads_Select::get_instance()->get_ad_by_method( $id, 'placement', $args ); |
| 69 | } |
| 70 | |
| 71 | /** |
| 72 | * return content of an ad placement |
| 73 | * |
| 74 | * @since 1.1.0 |
| 75 | * @param string $id slug of the ad placement |
| 76 | */ |
| 77 | function the_ad_placement($id = ''){ |
| 78 | echo get_ad_placement( $id ); |
| 79 | } |
| 80 | |
| 81 | /** |
| 82 | * return true if ads can be displayed |
| 83 | * |
| 84 | * @since 1.4.9 |
| 85 | * @return bool, true if ads can be displayed |
| 86 | */ |
| 87 | function advads_can_display_ads(){ |
| 88 | return Advanced_Ads::get_instance()->can_display_ads(); |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Are we currently on an AMP URL? |
| 93 | * Will always return `false` and show PHP Notice if called before the `wp` hook. |
| 94 | * |
| 95 | * @return bool true if amp url, false otherwise |
| 96 | */ |
| 97 | function advads_is_amp() { |
| 98 | global $pagenow; |
| 99 | if ( is_admin() |
| 100 | || is_embed() |
| 101 | || is_feed() |
| 102 | || ( isset( $pagenow ) && in_array( $pagenow, array( 'wp-login.php', 'wp-signup.php', 'wp-activate.php' ), true ) ) |
| 103 | || ( defined( 'REST_REQUEST' ) && REST_REQUEST ) |
| 104 | || ( defined( 'XMLRPC_REQUEST' ) && XMLRPC_REQUEST ) |
| 105 | ) { |
| 106 | return false; |
| 107 | } |
| 108 | |
| 109 | if ( ! did_action( 'wp' ) ) { |
| 110 | return false; |
| 111 | } |
| 112 | |
| 113 | return ( function_exists( 'is_amp_endpoint' ) && is_amp_endpoint() ) |
| 114 | || ( function_exists( 'is_wp_amp' ) && is_wp_amp() ) |
| 115 | || ( function_exists( 'ampforwp_is_amp_endpoint' ) && ampforwp_is_amp_endpoint() ) |
| 116 | || isset( $_GET [ 'wpamp' ] ); |
| 117 | } |
| 118 | |
| 119 | /** |
| 120 | * Test if a placement has ads. |
| 121 | * |
| 122 | * @return bool |
| 123 | */ |
| 124 | function placement_has_ads( $id = '' ) { |
| 125 | $args = array( |
| 126 | 'global_output' => false, |
| 127 | 'cache-busting' => 'ignore', |
| 128 | ); |
| 129 | return Advanced_Ads_Select::get_instance()->get_ad_by_method( $id, 'placement', $args ) != ''; |
| 130 | |
| 131 | } |
| 132 | |
| 133 | /** |
| 134 | * Test if a group has ads. |
| 135 | * |
| 136 | * @return bool |
| 137 | */ |
| 138 | function group_has_ads( $id = '' ) { |
| 139 | $args = array( |
| 140 | 'global_output' => false, |
| 141 | 'cache-busting' => 'ignore', |
| 142 | ); |
| 143 | return Advanced_Ads_Select::get_instance()->get_ad_by_method( $id, 'group', $args ) != ''; |
| 144 | } |
| 145 |