ads
3 months ago
groups
3 months ago
metaboxes
1 year ago
pages
3 months ago
placements
2 months ago
class-action-links.php
1 year ago
class-addon-box.php
1 year ago
class-addon-updater.php
3 months ago
class-admin-menu.php
3 months ago
class-admin-notices.php
1 year ago
class-ajax.php
3 months ago
class-assets.php
3 months ago
class-authors.php
1 year ago
class-compatibility.php
1 year ago
class-edd-updater.php
3 months ago
class-list-filters.php
2 months ago
class-marketing.php
1 year ago
class-metabox-ad-settings.php
1 year ago
class-metabox-ad.php
1 year ago
class-misc.php
1 year ago
class-page-quick-edit.php
1 year ago
class-plugin-installer.php
1 year ago
class-post-list.php
1 year ago
class-post-types.php
3 months ago
class-screen-options.php
3 months ago
class-settings.php
1 year ago
class-shortcode-creator.php
1 year ago
class-system-info.php
1 year ago
class-tinymce.php
2 years ago
class-translation-promo.php
1 year ago
class-upgrades.php
1 year ago
class-version-control.php
3 months ago
class-welcome.php
1 year ago
class-wordpress-dashboard.php
1 year ago
index.php
2 years ago
class-upgrades.php
203 lines
| 1 | <?php |
| 2 | /** |
| 3 | * The class is responsible for holding promoting upgrade related functionality. |
| 4 | * |
| 5 | * @package AdvancedAds |
| 6 | * @author Advanced Ads <info@wpadvancedads.com> |
| 7 | * @since 2.0.0 |
| 8 | */ |
| 9 | |
| 10 | namespace AdvancedAds\Admin; |
| 11 | |
| 12 | defined( 'ABSPATH' ) || exit; |
| 13 | |
| 14 | use AdvancedAds\Constants; |
| 15 | use AdvancedAds\Abstracts\Ad; |
| 16 | use AdvancedAds\Utilities\Conditional; |
| 17 | use AdvancedAds\Framework\Interfaces\Integration_Interface; |
| 18 | |
| 19 | /** |
| 20 | * Class upgrades |
| 21 | */ |
| 22 | class Upgrades implements Integration_Interface { |
| 23 | |
| 24 | /** |
| 25 | * Hook into WordPress. |
| 26 | * |
| 27 | * @return void |
| 28 | */ |
| 29 | public function hooks(): void { |
| 30 | // Show notice in Ad Parameters when someone uses an Ad Manager ad in the plain text code field. |
| 31 | add_filter( 'advanced-ads-ad-notices', [ $this, 'ad_notices' ], 10, 3 ); |
| 32 | |
| 33 | // Show AMP options on ad edit page of AdSense ads. |
| 34 | add_action( 'advanced-ads-gadsense-extra-ad-param', [ $this, 'adsense_type_amp_options' ] ); |
| 35 | |
| 36 | // Add Duplicate. |
| 37 | add_filter( 'post_row_actions', [ $this, 'render_duplicate_link' ], 10, 2 ); |
| 38 | add_filter( 'post_row_actions', [ $this, 'render_placement_duplicate_link' ], 10, 2 ); |
| 39 | add_action( 'post_submitbox_start', [ $this, 'render_duplicate_link_in_submit_box' ] ); |
| 40 | } |
| 41 | |
| 42 | /** |
| 43 | * Show an upgrade link |
| 44 | * |
| 45 | * @param string $title link text. |
| 46 | * @param string $url target URL. |
| 47 | * @param string $utm_campaign utm_campaign value to attach to the URL. |
| 48 | * |
| 49 | * @return void |
| 50 | */ |
| 51 | public static function upgrade_link( $title = '', $url = '', $utm_campaign = 'upgrade' ): void { |
| 52 | $title = ! empty( $title ) ? $title : __( 'Upgrade', 'advanced-ads' ); |
| 53 | $url = ! empty( $url ) ? $url : 'https://wpadvancedads.com/add-ons/'; |
| 54 | |
| 55 | $url = add_query_arg( |
| 56 | [ |
| 57 | 'utm_source' => 'advanced-ads', |
| 58 | 'utm_medium' => 'link', |
| 59 | 'utm_campaign' => $utm_campaign, |
| 60 | ], |
| 61 | $url |
| 62 | ); |
| 63 | |
| 64 | include ADVADS_ABSPATH . 'admin/views/upgrades/upgrade-link.php'; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Show an Advanced Ads Pro upsell pitch |
| 69 | * |
| 70 | * @param string $utm_campaign utm_campaign value to attach to the URL. |
| 71 | * |
| 72 | * @return void |
| 73 | */ |
| 74 | public static function pro_feature_link( $utm_campaign = '' ): void { |
| 75 | self::upgrade_link( |
| 76 | __( 'Pro Feature', 'advanced-ads' ), |
| 77 | 'https://wpadvancedads.com/advanced-ads-pro/', |
| 78 | $utm_campaign |
| 79 | ); |
| 80 | } |
| 81 | |
| 82 | /** |
| 83 | * Show notices in the Ad Parameters meta box |
| 84 | * |
| 85 | * @param array $notices Notices. |
| 86 | * @param array $box current meta box. |
| 87 | * @param Ad $ad post object. |
| 88 | * |
| 89 | * @return array |
| 90 | */ |
| 91 | public function ad_notices( $notices, $box, $ad ) { |
| 92 | // Show notice when someone uses an Ad Manager ad in the plain text code field. |
| 93 | if ( ! defined( 'AAGAM_VERSION' ) && 'ad-parameters-box' === $box['id'] ) { |
| 94 | if ( $ad->is_type( 'plain' ) && strpos( $ad->get_content(), 'div-gpt-ad-' ) ) { |
| 95 | $notices[] = [ |
| 96 | 'text' => sprintf( |
| 97 | /* translators: %1$s and %2$s are opening and closing <a> tags */ |
| 98 | esc_html__( 'This looks like a Google Ad Manager ad. Use the %1$sGAM Integration%2$s.', 'advanced-ads' ), |
| 99 | '<a href="https://wpadvancedads.com/add-ons/google-ad-manager/?utm_source=advanced-ads&utm_medium=link&utm_campaign=upgrade-ad-parameters-gam" target="_blank">', |
| 100 | '</a>' |
| 101 | ) . ' ' . __( 'A quick and error-free way of implementing ad units from your Google Ad Manager account.', 'advanced-ads' ), |
| 102 | ]; |
| 103 | } |
| 104 | } |
| 105 | |
| 106 | return $notices; |
| 107 | } |
| 108 | |
| 109 | /** |
| 110 | * AMP options for AdSense ads in the Ad Parameters on the ad edit page. |
| 111 | */ |
| 112 | public function adsense_type_amp_options() { |
| 113 | if ( ! defined( 'AAR_VERSION' ) && \Advanced_Ads_Checks::active_amp_plugin() ) { |
| 114 | include_once ADVADS_ABSPATH . 'admin/views/upgrades/adsense-amp.php'; |
| 115 | } |
| 116 | } |
| 117 | |
| 118 | /** |
| 119 | * Add the link to action list for post_row_actions |
| 120 | * |
| 121 | * @param array $actions list of existing actions. |
| 122 | * @param WP_Post $post Post object. |
| 123 | * |
| 124 | * @return array with actions. |
| 125 | */ |
| 126 | public function render_duplicate_link( $actions, $post ) { |
| 127 | if ( |
| 128 | ! defined( 'AAP_VERSION' ) |
| 129 | && Constants::POST_TYPE_AD === $post->post_type |
| 130 | && Conditional::user_can( 'advanced_ads_edit_ads' ) |
| 131 | ) { |
| 132 | $actions['copy-ad'] = $this->create_duplicate_link(); |
| 133 | } |
| 134 | |
| 135 | return $actions; |
| 136 | } |
| 137 | |
| 138 | /** |
| 139 | * Add the link to action list for placements. |
| 140 | * |
| 141 | * @param array $actions list of existing actions. |
| 142 | * @param WP_Post $post Post object. |
| 143 | * |
| 144 | * @return array with actions. |
| 145 | */ |
| 146 | public function render_placement_duplicate_link( $actions, $post ) { |
| 147 | if ( |
| 148 | ! defined( 'AAP_VERSION' ) |
| 149 | && Constants::POST_TYPE_PLACEMENT === $post->post_type |
| 150 | && Conditional::user_can( 'advanced_ads_edit_ads' ) |
| 151 | ) { |
| 152 | $actions['copy-ad'] = $this->create_duplicate_link( Constants::POST_TYPE_PLACEMENT ); |
| 153 | } |
| 154 | |
| 155 | return $actions; |
| 156 | } |
| 157 | |
| 158 | /** |
| 159 | * Add the link to the submit box on the ad edit screen. |
| 160 | */ |
| 161 | public function render_duplicate_link_in_submit_box() { |
| 162 | global $post; |
| 163 | if ( |
| 164 | ! defined( 'AAP_VERSION' ) |
| 165 | && 'edit' === $post->filter // only for already saved ads. |
| 166 | && Constants::POST_TYPE_AD === $post->post_type |
| 167 | && Conditional::user_can( 'advanced_ads_edit_ads' ) |
| 168 | ) { |
| 169 | ?> |
| 170 | <div> |
| 171 | <?php echo wp_kses_post( $this->create_duplicate_link() ); ?> |
| 172 | </div> |
| 173 | <?php |
| 174 | } |
| 175 | } |
| 176 | |
| 177 | /** |
| 178 | * Generate text and upgrade link for the Duplicate function |
| 179 | * |
| 180 | * @param string $post_type post type. |
| 181 | */ |
| 182 | public function create_duplicate_link( $post_type = Constants::POST_TYPE_AD ) { |
| 183 | ob_start(); |
| 184 | |
| 185 | $utm_campaign = ( Constants::POST_TYPE_PLACEMENT === $post_type ) ? 'duplicate-placement' : 'duplicate-ad'; |
| 186 | |
| 187 | self::upgrade_link( |
| 188 | null, |
| 189 | sprintf( |
| 190 | 'https://wpadvancedads.com/advanced-ads-pro/?utm_source=advanced-ads&utm_medium=link&utm_campaign=%s', |
| 191 | $utm_campaign |
| 192 | ), |
| 193 | $utm_campaign |
| 194 | ); |
| 195 | |
| 196 | return sprintf( |
| 197 | '%1$s (%2$s)', |
| 198 | esc_html__( 'Duplicate', 'advanced-ads' ), |
| 199 | trim( ob_get_clean() ) |
| 200 | ); |
| 201 | } |
| 202 | } |
| 203 |