name = $name; $this->function = $function; $this->file = $file; $this->minimumVersion = $minimumVersion; $this->levels = $levels; add_action( 'plugins_loaded', array( $this, 'init' ) ); } /** * Check addon requirements. * We do it on `plugins_loaded` hook. If earlier the core constants are still not defined. * * @since 1.0.0 * * @return void */ public function init() { if ( version_compare( PHP_VERSION, '7.0', '<' ) ) { $this->failPhp(); return; } // Since the version numbers may vary, we only want to compare the first 3 numbers. self::$aioseoVersion = defined( 'AIOSEO_VERSION' ) ? current( explode( '-', AIOSEO_VERSION ) ) : ''; if ( ! has_action( 'admin_notices', array( __CLASS__, 'adminNotices' ) ) ) { add_action( 'admin_notices', array( __CLASS__, 'adminNotices' ) ); } if ( empty( self::$aioseoVersion ) || version_compare( self::$aioseoVersion, $this->minimumVersion, '<' ) ) { $this->requiresPro(); add_filter( 'auto_update_plugin', array( $this, 'disableAutoUpdate' ), 10, 2 ); add_filter( 'plugin_auto_update_setting_html', array( $this, 'modifyAutoupdaterSettingHtml' ), 11, 2 ); return; } add_action( 'aioseo_loaded', $this->function, 10 ); } /** * Prints out all notices. * * @since 1.0.0 * * @return void */ public static function adminNotices() { // Double check we're actually in the admin before outputting anything. if ( ! is_admin() ) { return; } self::showAddonsNotice( 'FailPhpVersion', sprintf( // Translators: 1 - Opening link tag, 2 - Closing link tag. esc_html__( 'Your site is running an outdated version of PHP that is no longer supported and is not compatible with the following addons (%1$sRead more%2$s for additional information):', 'aioseo-addon' ), // phpcs:ignore Generic.Files.LineLength.MaxExceeded '', '' ) ); self::showAddonsNotice( 'FailUpdate', sprintf( // Translators: 1 - "All in One SEO 4.0.0". esc_html__( 'The following addons cannot be used, because they require an update to work with %1$s:', 'aioseo-addon' ), 'All in One SEO Pro ' . wp_kses_post( self::$aioseoVersion ) . '' // We need to put the name here in since the plugin is most likely not active. ) ); self::showAddonsNotice( 'FailActiveLicense', sprintf( // Translators: 1 - "All in One SEO", 2 - Opening HTML link tag, 3 - Closing HTML link tag. esc_html__( 'The following addons cannot be used, because they require an active license for %1$s. Your license is missing or has expired. To verify your subscription, please %2$svisit our website%3$s.', 'aioseo-addon' ), // phpcs:ignore Generic.Files.LineLength.MaxExceeded esc_html( defined( 'AIOSEO_PLUGIN_NAME' ) ? AIOSEO_PLUGIN_NAME : 'All in One SEO' ), '', // phpcs:ignore WordPress.Security.EscapeOutput, Generic.Files.LineLength.MaxExceeded '' ) ); self::showMinimumVersionAddonsNotice( 'FailProVersion', sprintf( // Translators: 1 - "All in One SEO 4.0.0". esc_html__( 'The following addons cannot be used, because they require %1$s or later to work:', 'aioseo-addon' ), 'All in One SEO Pro [minimumVersion]' ) ); self::showAddonsNotice( 'FailPlanExpired', sprintf( // Translators: 1 - Opening HTML link tag, 2 - Closing HTML link tag. esc_html__( 'The following addons cannot be used, because your plan has expired. To renew your subscription, please %1$svisit our website%2$s.', 'aioseo-addon' ), '', // phpcs:ignore WordPress.Security.EscapeOutput, Generic.Files.LineLength.MaxExceeded '' ) ); $level = ''; if ( self::$aioseoVersion ) { $level = aioseo()->internalOptions->internal->has( 'license' ) && aioseo()->internalOptions->internal->license->level ? aioseo()->internalOptions->internal->license->level : $level; if ( ! $level ) { if ( aioseo()->core->cache->get( 'failed_update' ) ) { return; } $level = esc_html__( 'Unlicensed', 'aioseo-addon' ); } } self::showAddonsNotice( 'FailPlanLevel', sprintf( // Translators: 1 - The current plan name, 2 - Opening HTML link tag, 3 - Closing HTML link tag. esc_html__( 'The following addons cannot be used, because your plan level %1$s does not include access to these addons. To upgrade your subscription, please %2$svisit our website%3$s.', 'aioseo-addon' ), // phpcs:ignore Generic.Files.LineLength.MaxExceeded '(' . ( ! empty( $level ) ? wp_kses_post( ucfirst( $level ) ) : '' ) . ')', '', // phpcs:ignore WordPress.Security.EscapeOutput, Generic.Files.LineLength.MaxExceeded '' ) ); } /** * Get the current notice. * * @since 1.0.0 * * @param string $noticeKey The notice key. * @return string The current notice. */ public static function getCurrentNotice( $noticeKey ) { $noticeKey = 'aioseoAddon' . $noticeKey; if ( empty( self::$addonNotices[ $noticeKey ] ) ) { return ''; } return current( self::$addonNotices[ $noticeKey ] ); } /** * Get the URL for the current notice. * * @since 1.0.0 * * @param string $uri The URL to append to the marketing site. * @param string $noticeKey The notice key. * @param string $content The UTM content parameter. * @return string The current notice. */ public static function getUtmUrl( $uri, $noticeKey, $content ) { $url = 'https://aioseo.com/' . $uri; // Generate the new arguments. $args = [ 'utm_source' => 'WordPress', 'utm_campaign' => 'addon', 'utm_medium' => self::getCurrentNotice( $noticeKey ), 'utm_content' => $content ]; // Return the new URL. $url = add_query_arg( $args, $url ); return esc_url( $url ); } /** * Adds a generic notice for an addon. * * @since 1.0.0 * * @param string $noticeKey The notice key. * @param string $addonName The addon name. * @return void */ public function addAddonNotice( $noticeKey, $addonName ) { if ( $this->disableNotices ) { return; } $noticeKey = 'aioseoAddon' . $noticeKey; if ( empty( self::$addonNotices[ $noticeKey ] ) ) { self::$addonNotices[ $noticeKey ] = array(); } self::$addonNotices[ $noticeKey ][] = [ 'addonName' => $addonName, 'minimumVersion' => $this->minimumVersion ]; } /** * HTML for the addon notice. * * @since 1.0.0 * * @param string $noticeKey The notice key. * @param string $message The message to output. * @return void */ public static function showAddonsNotice( $noticeKey, $message ) { $noticeKey = 'aioseoAddon' . $noticeKey; if ( empty( self::$addonNotices[ $noticeKey ] ) ) { return; } echo '
'; echo wp_kses_post( $message ); echo '
'; $addonsList = wp_list_pluck( self::$addonNotices[ $noticeKey ], 'addonName' ); $addonsList = implode( ''; echo wp_kses_post( $versionMessage ); echo '
'; $addonsList = implode( '