admin-scripts.php
2 years ago
class-wpcode-admin-page-loader-lite.php
9 months ago
class-wpcode-connect.php
2 years ago
class-wpcode-metabox-snippets-lite.php
1 year ago
class-wpcode-usage-tracking-lite.php
3 years ago
notices.php
1 year ago
notices.php
156 lines
| 1 | <?php |
| 2 | /** |
| 3 | * Lite-specific admin notices. |
| 4 | */ |
| 5 | |
| 6 | if ( ! defined( 'ABSPATH' ) ) { |
| 7 | exit; |
| 8 | } |
| 9 | |
| 10 | add_action( 'admin_init', 'wpcode_maybe_add_library_connect_notice' ); |
| 11 | add_action( 'wpcode_admin_page', 'wpcode_maybe_add_lite_top_bar_notice', 4 ); |
| 12 | add_action( 'wpcode_admin_page_content_wpcode-headers-footers', 'wpcode_headers_footers_bottom_notice', 250 ); |
| 13 | |
| 14 | /** |
| 15 | * Show a prompt to connect to the WPCode Library to get access to more snippets. |
| 16 | * |
| 17 | * @return void |
| 18 | */ |
| 19 | function wpcode_maybe_add_library_connect_notice() { |
| 20 | if ( wpcode()->library_auth->has_auth() || ! isset( $_GET['page'] ) || 0 !== strpos( $_GET['page'], 'wpcode' ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash |
| 21 | return; |
| 22 | } |
| 23 | // Don't show if in headers & footers mode only. |
| 24 | if ( wpcode()->settings->get_option( 'headers_footers_mode' ) ) { |
| 25 | return; |
| 26 | } |
| 27 | |
| 28 | $settings_url = add_query_arg( |
| 29 | array( |
| 30 | 'page' => 'wpcode-settings', |
| 31 | ), |
| 32 | admin_url( 'admin.php' ) |
| 33 | ); |
| 34 | |
| 35 | $snippets_count = wpcode()->library->get_snippets_count(); |
| 36 | // Translators: more here is used in the sense of "get access to more snippets" and gets replaced with the number of snippets if the library items are loaded correctly. |
| 37 | $more = $snippets_count > 0 ? $snippets_count : __( 'more', 'insert-headers-and-footers' ); |
| 38 | |
| 39 | WPCode_Notice::info( |
| 40 | sprintf( |
| 41 | // Translators: %1$s and %2$s add a link to the settings page. %3$s and %4$s make the text bold. %6$s is replaced with the number of snippets and %5$s adds a "new" icon. |
| 42 | __( '%5$s%1$sConnect to the WPCode Library%2$s to get access to %3$s%6$s FREE snippets%4$s!', 'insert-headers-and-footers' ), |
| 43 | '<a href="' . $settings_url . '" class="wpcode-start-auth">', |
| 44 | '</a>', |
| 45 | '<strong>', |
| 46 | '</strong>', |
| 47 | '<span class="wpcode-icon-new"> NEW!</span>', |
| 48 | $more |
| 49 | ), |
| 50 | array( |
| 51 | 'dismiss' => WPCode_Notice::DISMISS_GLOBAL, |
| 52 | 'slug' => 'wpcode-library-connect-lite', |
| 53 | ) |
| 54 | ); |
| 55 | } |
| 56 | |
| 57 | /** |
| 58 | * Add a notice to consider more features with offer. |
| 59 | * |
| 60 | * @return void |
| 61 | */ |
| 62 | function wpcode_maybe_add_lite_top_bar_notice() { |
| 63 | // Only add this to the WPCode pages. |
| 64 | if ( ! isset( $_GET['page'] ) || 0 !== strpos( $_GET['page'], 'wpcode' ) ) { // phpcs:ignore WordPress.Security.NonceVerification.Recommended, WordPress.Security.ValidatedSanitizedInput.InputNotSanitized, WordPress.Security.ValidatedSanitizedInput.MissingUnslash |
| 65 | return; |
| 66 | } |
| 67 | // Don't show in H&F mode. |
| 68 | if ( wpcode()->settings->get_option( 'headers_footers_mode' ) ) { |
| 69 | return; |
| 70 | } |
| 71 | |
| 72 | $screen = get_current_screen(); |
| 73 | if ( isset( $screen->id ) && false !== strpos( $screen->id, 'code-snippets_page_wpcode-' ) ) { |
| 74 | $screen = str_replace( 'code-snippets_page_wpcode-', '', $screen->id ); |
| 75 | } else { |
| 76 | $screen = 'snippets-list'; |
| 77 | } |
| 78 | |
| 79 | $upgrade_url = wpcode_utm_url( |
| 80 | 'https://wpcode.com/lite/', |
| 81 | 'top-notice', |
| 82 | $screen |
| 83 | ); |
| 84 | |
| 85 | WPCode_Notice::top( |
| 86 | sprintf( |
| 87 | // Translators: %1$s and %2$s add a link to the upgrade page. %3$s and %4$s make the text bold. |
| 88 | __( '%3$sYou\'re using WPCode Lite%4$s. To unlock more features consider %1$supgrading to Pro%2$s.', 'insert-headers-and-footers' ), |
| 89 | '<a href="' . $upgrade_url . '" target="_blank" rel="noopener noreferrer">', |
| 90 | '</a>', |
| 91 | '<strong>', |
| 92 | '</strong>' |
| 93 | ), |
| 94 | array( |
| 95 | 'dismiss' => WPCode_Notice::DISMISS_USER, |
| 96 | 'slug' => 'consider-upgrading', |
| 97 | ) |
| 98 | ); |
| 99 | } |
| 100 | |
| 101 | /** |
| 102 | * Show a notice with more features at the bottom of the Headers & Footers page. |
| 103 | * |
| 104 | * @return void |
| 105 | */ |
| 106 | function wpcode_headers_footers_bottom_notice() { |
| 107 | // Don't show if in headers & footers mode only. |
| 108 | if ( wpcode()->settings->get_option( 'headers_footers_mode' ) ) { |
| 109 | return; |
| 110 | } |
| 111 | // Don't show if other notices were already displayed on the page. |
| 112 | if ( ! empty( wpcode()->notice->notices ) ) { |
| 113 | return; |
| 114 | } |
| 115 | |
| 116 | $html = '<h3>' . esc_html__( 'Get WPCode Pro and Unlock all the Powerful Features', 'insert-headers-and-footers' ) . '</h3>'; |
| 117 | $html .= '<div class="wpcode-features-list">'; |
| 118 | $html .= '<ul>'; |
| 119 | $html .= '<li>' . esc_html__( 'Save & Reuse snippets in your private Cloud Library', 'insert-headers-and-footers' ) . '</li>'; |
| 120 | $html .= '<li>' . esc_html__( 'Add page-specific scripts when editing a post/page.', 'insert-headers-and-footers' ) . '</li>'; |
| 121 | $html .= '<li>' . esc_html__( 'Track all snippet changes with Advanced Code Revisions', 'insert-headers-and-footers' ) . '</li>'; |
| 122 | $html .= '</ul>'; |
| 123 | $html .= '<ul>'; |
| 124 | $html .= '<li>' . esc_html__( 'Load snippets by device (mobile/desktop) with 1-click.', 'insert-headers-and-footers' ) . '</li>'; |
| 125 | $html .= '<li>' . esc_html__( 'Easily insert and reuse content with Custom Shortcodes.', 'insert-headers-and-footers' ) . '</li>'; |
| 126 | $html .= '<li>' . esc_html__( 'Precisely track eCommerce conversions for WooCommerce and EDD.', 'insert-headers-and-footers' ) . '</li>'; |
| 127 | $html .= '</ul>'; |
| 128 | $html .= '</div>'; |
| 129 | $html .= sprintf( |
| 130 | '<p><a href="%1$s" target="_blank" rel="noopener noreferrer">%2$s</a></p>', |
| 131 | wpcode_utm_url( 'https://wpcode.com/lite/', 'headers-footers', 'notice', 'get-wpcode-pro' ), |
| 132 | esc_html__( 'Get WPCode Pro Today and Unlock all the Powerful Features »', 'insert-headers-and-footers' ) |
| 133 | ); |
| 134 | $html .= '<p>'; |
| 135 | $html .= sprintf( |
| 136 | // Translators: Placeholders make the text bold. |
| 137 | esc_html__( '%1$sBonus:%2$s WPCode Lite users get %3$s$50 off regular price%4$s, automatically applied at checkout', 'insert-headers-and-footers' ), |
| 138 | '<strong>', |
| 139 | '</strong>', |
| 140 | '<strong style="color:#59A56D;">', |
| 141 | '</strong>' |
| 142 | ); |
| 143 | $html .= '</p>'; |
| 144 | |
| 145 | // Add our custom notice for this page. |
| 146 | WPCode_Notice::info( |
| 147 | $html, |
| 148 | array( |
| 149 | 'slug' => 'ihaf-snippets', |
| 150 | 'dismiss' => WPCode_Notice::DISMISS_USER, |
| 151 | ) |
| 152 | ); |
| 153 | // Display notice we just added so that scripts are loaded. |
| 154 | wpcode()->notice->display(); |
| 155 | } |
| 156 |