ads
1 week ago
groups
1 week ago
metaboxes
1 year ago
pages
3 months ago
placements
1 week ago
class-action-links.php
1 week ago
class-addon-box.php
1 year ago
class-addon-updater.php
3 months ago
class-admin-menu.php
1 week ago
class-admin-notices.php
1 year ago
class-ajax.php
3 months ago
class-assets.php
1 week ago
class-authors.php
1 year ago
class-edd-updater.php
4 weeks ago
class-list-filters.php
1 week 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 week 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
1 week 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-action-links.php
176 lines
| 1 | <?php |
| 2 | /** |
| 3 | * The class manages various admin action links, feedback submission and text overrides in footer. |
| 4 | * |
| 5 | * @package AdvancedAds |
| 6 | * @author Advanced Ads <info@wpadvancedads.com> |
| 7 | * @since 1.47.0 |
| 8 | */ |
| 9 | |
| 10 | namespace AdvancedAds\Admin; |
| 11 | |
| 12 | use WP_User; |
| 13 | use Advanced_Ads; |
| 14 | use AdvancedAds\Utilities\Conditional; |
| 15 | use AdvancedAds\Framework\Utilities\Params; |
| 16 | use AdvancedAds\Framework\Interfaces\Integration_Interface; |
| 17 | |
| 18 | defined( 'ABSPATH' ) || exit; |
| 19 | |
| 20 | /** |
| 21 | * Action Links. |
| 22 | */ |
| 23 | class Action_Links implements Integration_Interface { |
| 24 | |
| 25 | /** |
| 26 | * Hook into WordPress. |
| 27 | * |
| 28 | * @return void |
| 29 | */ |
| 30 | public function hooks(): void { |
| 31 | add_filter( 'plugin_action_links_' . ADVADS_PLUGIN_BASENAME, [ $this, 'add_links' ] ); |
| 32 | add_filter( 'admin_footer', [ $this, 'add_deactivation_popup' ] ); |
| 33 | add_filter( 'admin_footer_text', [ $this, 'admin_footer_text' ], 100 ); |
| 34 | add_action( 'wp_ajax_advads_send_feedback', [ $this, 'send_feedback' ] ); |
| 35 | } |
| 36 | |
| 37 | /** |
| 38 | * Add links to the plugins list |
| 39 | * |
| 40 | * @param array $links array of links for the plugins, adapted when the current plugin is found. |
| 41 | * |
| 42 | * @return array |
| 43 | */ |
| 44 | public function add_links( $links ): array { |
| 45 | // Early bail!! |
| 46 | if ( ! is_array( $links ) ) { |
| 47 | return $links; |
| 48 | } |
| 49 | |
| 50 | // Add support page link. |
| 51 | $support_link = sprintf( |
| 52 | '<a href="%1$s">%2$s</a>', |
| 53 | esc_url( admin_url( 'admin.php?page=advanced-ads-settings#top#support' ) ), |
| 54 | __( 'Support', 'advanced-ads' ) |
| 55 | ); |
| 56 | |
| 57 | // Add add-ons link. |
| 58 | $extend_link = defined( 'AAP_VERSION' ) |
| 59 | ? '<a href="https://wpadvancedads.com/add-ons/?utm_source=advanced-ads&utm_medium=link&utm_campaign=plugin-page-add-ons" target="_blank">' . __( 'Add-Ons', 'advanced-ads' ) . '</a>' |
| 60 | : '<a href="https://wpadvancedads.com/add-ons/all-access/?utm_source=advanced-ads&utm_medium=link&utm_campaign=plugin-page-features" target="_blank" class="aa-get-pro">' . __( 'See Pro Features', 'advanced-ads' ) . '</a>'; |
| 61 | |
| 62 | array_unshift( $links, $support_link, $extend_link ); |
| 63 | |
| 64 | return $links; |
| 65 | } |
| 66 | |
| 67 | /** |
| 68 | * Display deactivation logic on plugins page |
| 69 | * |
| 70 | * @since 1.7.14 |
| 71 | * |
| 72 | * @return void |
| 73 | */ |
| 74 | public function add_deactivation_popup(): void { |
| 75 | $screen = get_current_screen(); |
| 76 | if ( ! isset( $screen->id ) || ! in_array( $screen->id, [ 'plugins', 'plugins-network' ], true ) ) { |
| 77 | return; |
| 78 | } |
| 79 | |
| 80 | $from = ''; |
| 81 | $email = ''; |
| 82 | $current_user = wp_get_current_user(); |
| 83 | if ( $current_user instanceof WP_User ) { |
| 84 | $from = sprintf( '%1$s <%2$s>', $current_user->user_nicename, trim( $current_user->user_email ) ); |
| 85 | $email = $current_user->user_email; |
| 86 | } |
| 87 | |
| 88 | include ADVADS_ABSPATH . 'views/admin/feedback-disable.php'; |
| 89 | } |
| 90 | |
| 91 | /** |
| 92 | * Overrides WordPress text in Footer |
| 93 | * |
| 94 | * @param string $text The footer text. |
| 95 | * |
| 96 | * @return string |
| 97 | */ |
| 98 | public function admin_footer_text( $text ): string { |
| 99 | if ( Conditional::is_screen_advanced_ads() ) { |
| 100 | return sprintf( |
| 101 | /* translators: %1$s is the URL to add a new review */ |
| 102 | __( 'Thank the developer with a ★★★★★ review on <a href="%1$s" target="_blank">wordpress.org</a>', 'advanced-ads' ), |
| 103 | 'https://wordpress.org/support/plugin/advanced-ads/reviews/#new-post' |
| 104 | ); |
| 105 | } |
| 106 | |
| 107 | return (string) $text; |
| 108 | } |
| 109 | |
| 110 | /** |
| 111 | * Send feedback via email |
| 112 | * |
| 113 | * @since 1.7.14 |
| 114 | * |
| 115 | * @return void |
| 116 | */ |
| 117 | public function send_feedback(): void { |
| 118 | $data = Params::post( 'formdata' ); |
| 119 | if ( ! $data ) { |
| 120 | wp_die(); |
| 121 | } |
| 122 | |
| 123 | wp_parse_str( wp_unslash( $data ), $form ); |
| 124 | |
| 125 | if ( ! wp_verify_nonce( $form['advanced_ads_disable_form_nonce'], 'advanced_ads_disable_form' ) ) { |
| 126 | wp_die(); |
| 127 | } |
| 128 | |
| 129 | $email = trim( $form['advanced_ads_disable_reply_email'] ); |
| 130 | if ( empty( $email ) || ! is_email( $email ) ) { |
| 131 | die(); |
| 132 | } |
| 133 | |
| 134 | $text = ''; |
| 135 | $headers = []; |
| 136 | $options = Advanced_Ads::get_instance()->internal_options(); |
| 137 | $installed = isset( $options['installed'] ) ? gmdate( 'd.m.Y', $options['installed'] ) : '–'; |
| 138 | $from = $form['advanced_ads_disable_from'] ?? ''; |
| 139 | $subject = ( $form['advanced_ads_disable_reason'] ?? '(no reason given)' ) . ' (Advanced Ads)'; |
| 140 | |
| 141 | if ( isset( $form['advanced_ads_disable_text'] ) ) { |
| 142 | $text = implode( "\n\r", $form['advanced_ads_disable_text'] ); |
| 143 | } |
| 144 | $text .= "\n\n" . home_url() . " ($installed)"; |
| 145 | |
| 146 | // The user clicked on the "don’t disable" button or if an address is given in the form then use that one. |
| 147 | if ( |
| 148 | isset( $form['advanced_ads_disable_reason'] ) && |
| 149 | 'get help' === $form['advanced_ads_disable_reason'] |
| 150 | ) { |
| 151 | $current_user = wp_get_current_user(); |
| 152 | $name = ( $current_user instanceof WP_User ) ? $current_user->user_nicename : ''; |
| 153 | $from = $name . ' <' . $email . '>'; |
| 154 | $is_german = ( preg_match( '/\.de$/', $from ) || 'de_' === substr( get_locale(), 0, 3 ) || 'de_' === substr( get_user_locale(), 0, 3 ) ); |
| 155 | |
| 156 | if ( '' !== trim( $form['advanced_ads_disable_text'][0] ?? '' ) ) { |
| 157 | $text .= $is_german |
| 158 | ? "\n\n Hilfe ist auf dem Weg." |
| 159 | : "\n\n Help is on its way."; |
| 160 | } else { |
| 161 | $text .= $is_german |
| 162 | ? "\n\n Vielen Dank für das Feedback." |
| 163 | : "\n\n Thank you for your feedback."; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | if ( $from ) { |
| 168 | $headers[] = "From: $from"; |
| 169 | $headers[] = "Reply-To: $from"; |
| 170 | } |
| 171 | |
| 172 | wp_mail( 'support@wpadvancedads.com', $subject, $text, $headers ); |
| 173 | die(); |
| 174 | } |
| 175 | } |
| 176 |