128,
'meta-title' => 128,
'meta-description' => 256,
'keywords' => 512,
'facebook-title' => 128,
'facebook-description' => 256,
'twitter-title' => 128,
'twitter-description' => 256,
'title' => 256,
'alt-text' => 256,
'caption' => 256,
'description' => 512,
'fallback' => 512,
);
// =========================================================================================== \\
/**
* function to return the change log of the plugin
* @return array[] the change log of the plugin
*/
function ai4seo_get_change_log(): array {
return [
[
'date' => 'November 20th, 2025',
'version' => '2.2.2',
'important' => true,
'updates' => [
'Bug Fixes & Maintenance: Fixed 9 minor bugs, implemented 3 usability improvements, and resolved 2 security issues.'
],
],
[
'date' => 'November 15th, 2025',
'version' => '2.2.1',
'important' => true,
'updates' => [
'Bug Fixes & Maintenance: Fixed 5 minor bugs',
],
],
[
'date' => 'November 14th, 2025',
'version' => '2.2.0',
'important' => true,
'updates' => [
'Changed how Credits are consumed. Credits are now charged per generated field instead of per entry. Use the “Active Meta Tags” and “Active Media Attributes” settings to control which fields are generated and how many Credits each action requires.',
'Added Focus Keyphrase generation, editing, and syncing for Yoast SEO and RankMath.',
'Added Meta Keywords generation, editing, and front-end output.',
'Added WooCommerce price inclusion modes for AI-generated metadata (Never, Fixed Price, Dynamic Price).',
'Added additional “Generate with AI” buttons inside the Gutenberg editor when RankMath is active.',
'Added “Generate with AI” buttons for Focus Keyphrase (Yoast SEO) and Focus Keyword (RankMath) inside their editors.',
'Added a filter bar to the Posts and Media views including SEO-status filters and a text search.',
'Added placeholder support for prefixes and suffixes across all syntaxes ({TITLE}, [TITLE], %%TITLE%% and their placeholder variants).',
'Added a setting to include existing values when generating metadata and media attributes (Basic Plan+).',
'Added a setting to enable enhanced entity recognition for media attributes (Pro Plan+).',
'Added a setting to enable advanced celebrity face recognition for media attributes (Premium Plan+).',
'Added configurable meta tag fallback rules to reuse existing values when no generated data is available.',
'Added a toggle to control JavaScript-based alt text injection separately from render-level injection.',
'Added a troubleshooting toggle to pause database refresh operations during debugging.',
'Added the “Active Meta Tags” setting to control which meta tags the plugin should generate.',
'Added the “Active Post Types” setting to define which post types the plugin should process.',
'Added a reminder and one-click removal option for previously generated SEO-relevant data within the SEO Autopilot modal.',
'Added a “Generate Data for X Empty Fields” button in the Metadata and Media Attribute Editors.',
'Added a “Save & edit next” button in the Metadata and Media Attribute Editors for faster sequential editing.',
'Added a “Retry all failed” quick action to the Dashboard when failed entries are detected.',
'Added Credits badges across the plugin UI to indicate the cost of generation actions.',
'Added an “SEO-Expert Concierge” card to the Dashboard with direct contact options.',
'Submit and Abort buttons are now sticky for easier access during editing.',
'Bug Fixes & Maintenance: Fixed 21 minor bugs, implemented 29 usability improvements, implemented 35 stability improvements, and resolved 8 security issues.'
],
],
[
'date' => 'September 23th, 2025',
'version' => '2.1.5',
'important' => false,
'updates' => [
'Added a new feature to easily retrieve lost license data. Go to your Account page, click "Lost your license data?", and follow the instructions.',
'Bug Fixes & Maintenance: Fixed 2 minor bugs and implemented 4 usability improvements.'
],
],
[
'date' => 'August 28th, 2025',
'version' => '2.1.3',
'important' => true,
'updates' => [
'Dashboard now refreshes automatically; manual page reload is no longer required.',
'Added compatibility with the SEOKey plugin.',
'Alt Text Injection is now disabled by default. To re-enable, go to Settings > Show Advanced Settings (top right) > Troubleshooting & Experimental > Alt Text Injection.',
'Added a submenu for direct plugin access via the WordPress admin menu.',
'Added a "Refresh" button to dashboard statistics. Recommended for large sites (>10,000 entries) to update statistics on demand.',
'Added a new FAQ area under Help > Troubleshooting, covering common problems and solutions.',
'Bug Fixes & Maintenance: Fixed 11 minor bugs, implemented 13 performance and usability improvements, and resolved 2 security issues.',
]
],
[
'date' => 'August 3rd, 2025',
'version' => '2.1.0',
'important' => true,
'updates' => [
'Added "Generate with AI" buttons in the media section of the Gutenberg editor, allowing users to generate media attributes directly from the editor.',
'Improved context awareness for pages, posts, and products, especially for content with short text. Ensures AI-generated metadata is more relevant and tailored.',
'Added a setting for render-level alt text injection. This checkbox setting (enabled by default) ensures images always have the correct alt text, even if themes or other mechanisms fail to display it.',
'Added a setting for render-level image title injection. Includes a select input to choose what should be injected as the title attribute: Disabled, Inject image title, Inject alt text (default), Inject caption, or Inject image description.',
'Added a setting to the "SEO Autopilot" modal that allows users to customize the reference time used by the "Generate Metadata for" option. This gives more precise control over how new and old entries are distinguished.',
'Added an "Export/Import" button to the plugin settings, enabling users to export their configuration and import it on another website. Useful for SEO and web agencies managing multiple sites.',
'Added a "Restore Default" button to the plugin settings.',
'Added a "Show/Hide Advanced Settings" toggle in the plugin settings. Some advanced settings are now hidden by default to simplify the interface for most users.',
'Made setting descriptions more concise and user-friendly. Rearranged several settings for improved clarity and usability.',
'Private or pending posts, pages, and attachments are now ignored by the plugin, preventing them from being processed.',
#'The plugin now indicates posts, pages, and attachments correctly when ignored by the SEO Autopilot, fully respecting the user\'s selection and settings.',
'Improved UX: The AI for SEO sidebar is now sticky on desktop, keeping it visible during page scrolling for easier navigation.',
'Changed how plugin notifications are handled. All notifications are now indicated by a red bubble in the admin menu. Detailed notices can be viewed in the AI for SEO dashboard.',
'Added new notifications:
Insufficient credits balance.
Overview of missing entries to generate.
WPML plugin detected.
SEO Autopilot needing attention.
New major plugin updates.
Ongoing promos and discounts.
And others.
',
'Bug Fixes & Maintenance: Fixed 17 minor bugs, added 6 quality-of-life improvements, implemented 3 performance optimizations, and 2 security updates.'
]
],
[
'date' => 'July 1st, 2025',
'version' => '2.0.7',
'important' => false,
'updates' => [
'Bug Fixes & Maintenance: Fixed 7 minor bugs, added 3 quality of life improvements, and implemented security updates.'
]
],
[
'date' => 'June 23nd, 2025',
'version' => '2.0.6',
'important' => false,
'updates' => [
'Bug Fixes & Maintenance: Fixed 3 minor bug'
]
],
[
'date' => 'June 22nd, 2025',
'version' => '2.0.5',
'important' => true,
'updates' => [
'Added a setting to force the image upload to use either the image url only or convert the contents to base64. This can be useful for users who experience issues with the generation of media attributes.',
'Added support for AVIF image files',
'Bug Fixes & Maintenance: Fixed 11 minor bugs and implemented security updates.'
]
],
[
'date' => 'May 9th, 2025',
'version' => '2.0.4',
'important' => false,
'updates' => [
'Added support for NextGen Gallery: The plugin now recognizes and processes media attributes for images created with the NextGen Gallery plugin. Use the new "Import" button in the media page to import all images from the NextGen Gallery into the *AI for SEO* plugin.',
'Bug Fixes & Maintenance: Fixed 2 minor bugs'
]
],
[
'date' => 'May 4th, 2025',
'version' => '2.0.3',
'important' => false,
'updates' => [
'SEO Autopilot now more accurately reflects its current status and includes an option to immediately schedule the next run.',
'Bug Fixes & Maintenance: Fixed 15 minor bugs, corrected typos, and implemented security updates.'
]
],
[
'date' => 'April 08th, 2025',
'version' => '2.0.2',
'important' => false,
'updates' => [
'Improved Prefix & Suffix Support: Prefixes and suffixes are now correctly applied when using the "Generate with AI" button in both the Metadata Editor and the Attachment Attributes Editor.',
'Enhanced Mobile UX: Better responsiveness and usability on the Pages / Posts and Media Files views for mobile devices.',
'Account Page Improvements: Added direct buttons for managing your active subscription and customizing Pay-As-You-Go settings.',
'Updated Help Section: Improved help content and clearer "First Steps" guidance for new users.',
'Bug Fixes & Maintenance: Fixed 11 minor bugs, corrected typos, and implemented security updates.'
]
],
[
'date' => 'March 20th, 2025',
'version' => '2.0.0',
'important' => true,
'updates' => [
'Complete UI/UX Overhaul: The look, feel, design, layout, and navigation of the plugin have been completely redesigned.',
'Enhanced Mobile Experience: Improved usability and user experience for mobile users.',
'New "Account" Page: Users can now manage their license key directly from this page.',
'Incognito Mode: SEO and web agencies can hide the plugin from other users/admins (available in the new "Account" page).',
'White-Label Feature: SEO and web agencies can rebrand the plugin with their own name or further hide it from other users/admins (available in the new "Account" page).',
'Customizable Generator Hints: Added a setting to modify or disable generator hints in the source code for additional privacy (available in the "Account" page).',
'Privacy & Data Policy Update: Moved to the new "Account" page.',
'New Metadata Customization Options: Added settings to apply prefixes and suffixes to metadata and media attributes.',
'Advanced Media Attribute Control: New setting allows users to specify which media attributes the plugin should use.',
'"SEO Autopilot" Feature: Replaces bulk generation checkboxes with a more intuitive and easy-to-use interface, directly accessible from the dashboard.',
'"Recent Activity" Dashboard Section: Track all manual and automatic metadata and media attribute generations in one place.',
'Implemented new ways to get credits:
* Introduced Credit Packs, allowing users to purchase additional credits as needed.
* Added a Pay-As-You-Go option for automatic credit refills when running low.
* All credit purchasing options are now combined in a "Get more Credits" modal, accessible from the dashboard.
The focus keyphrase is added to the meta title and meta description for best SEO results. Make sure to first generate the keyphrase before generating the meta title and meta description or just generate all at once.", "ai-for-seo"),
"api-identifier" => "focus_keyphrase",
"flat-credits-cost" => 2,
),
"meta-title" => array(
"name" => esc_html__("Meta Title", "ai-for-seo"),
"icon" => "globe",
"input" => "textarea",
"hint" => __("Best Practice: A unique and concise title for this entry, which will be displayed on search engine results pages (SERPs) and in the browser tab. This helps users understand your content and enhances visibility.
The AI aims to generate a meta title with an optimal length of 50 to 60 characters.
The meta title is added to the title tag of your website.", "ai-for-seo"),
"api-identifier" => "meta_title",
"output-tag-type" => "title",
"output-tag-identifier" => "",
"meta-tag-regex" => '/(.*?)<\/title>/is',
"meta-tag-regex-match-index" => 1,
"flat-credits-cost" => 1,
),
"meta-description" => array(
"name" => esc_html__("Meta Description", "ai-for-seo"),
"icon" => "globe",
"input" => "textarea",
"hint" => __("Best Practice: A compelling and relevant meta description for your page or post, which will appear on search engine results pages (SERPs) beneath the meta title. This description provides a summary of your content, helping to attract clicks and improve visibility.
The AI aims to generate a meta description with an optimal length of 135 to 150 characters.
The meta description is added to the meta description tag of your website.", "ai-for-seo"),
"api-identifier" => "meta_description",
"output-tag-type" => "meta name",
"output-tag-identifier" => "description",
"meta-tag-regex" => '/]*name=(["\'])description\1[^>]*content=(["\'])(.*?)\2[^>]*>/i',
"meta-tag-regex-match-index" => 3,
"flat-credits-cost" => 2,
),
"keywords" => array(
"name" => esc_html__("Keywords", "ai-for-seo"),
"icon" => "hashtag",
"input" => "textarea",
"hint" => __("Best Practice: Provide a concise, comma-separated list of the most relevant SEO keywords for this entry. Focus on specific phrases that best describe the content and avoid duplicates or keyword stuffing.
The meta keywords are added to the meta keywords tag of your website.", "ai-for-seo"),
"api-identifier" => "meta_keywords",
"output-tag-type" => "meta name",
"output-tag-identifier" => "keywords",
"meta-tag-regex" => '/]*name=(["\'])keywords\1[^>]*content=(["\'])(.*?)\2[^>]*>/i',
"meta-tag-regex-match-index" => 3,
"flat-credits-cost" => 1,
),
"facebook-title" => array(
"name" => esc_html__("Facebook Title", "ai-for-seo"),
"icon" => "square-facebook",
"input" => "textarea",
"hint" => __("Best Practice: This title will be displayed as the headline in the preview when your content is shared on Facebook, helping to capture attention and increase engagement.
The AI aims to generate a Facebook title with an optimal length of 50 to 60 characters.
The Facebook title is added to the og:title tag of your website.", "ai-for-seo"),
"api-identifier" => "meta_facebook_title",
"output-tag-type" => "meta property",
"output-tag-identifier" => "og:title",
"meta-tag-regex" => '/]*property=(["\'])og:title\1[^>]*content=(["\'])(.*?)\2[^>]*>/i',
"meta-tag-regex-match-index" => 3,
"flat-credits-cost" => 1,
),
"facebook-description" => array(
"name" => esc_html__("Facebook Description", "ai-for-seo"),
"icon" => "square-facebook",
"input" => "textarea",
"hint" => __("Best Practice: This description will appear in the preview when your content is shared, providing a summary that encourages users to engage with your content.
The AI aims to generate a Facebook description with an optimal length of 55 to 65 characters.
The Facebook description is added to the og:description tag of your website.", "ai-for-seo"),
"api-identifier" => "meta_facebook_description",
"output-tag-type" => "meta property",
"output-tag-identifier" => "og:description",
"meta-tag-regex" => '/]*property=(["\'])og:description\1[^>]*content=(["\'])(.*?)\2[^>]*>/i',
"meta-tag-regex-match-index" => 3,
"flat-credits-cost" => 1,
),
"twitter-title" => array(
"name" => esc_html__("Twitter/X Title", "ai-for-seo"),
"icon" => "square-twitter-x",
"input" => "textarea",
"hint" => __("Best Practice: An attention-grabbing title for your page or post, optimized for sharing on Twitter/X. This title will be displayed as the headline in the preview when your content is tweeted, helping to increase visibility and encourage clicks.
The AI aims to generate a Twitter/X title with an optimal length of 50 to 60 characters.
The Twitter/X title is added to the twitter:title tag of your website.", "ai-for-seo"),
"api-identifier" => "meta_twitter_title",
"output-tag-type" => "meta name",
"output-tag-identifier" => "twitter:title",
"meta-tag-regex" => '/]*name=(["\'])twitter:title\1[^>]*content=(["\'])(.*?)\2[^>]*>/i',
"meta-tag-regex-match-index" => 3,
"flat-credits-cost" => 1,
),
"twitter-description" => array(
"name" => esc_html__("Twitter/X Description", "ai-for-seo"),
"icon" => "square-twitter-x",
"input" => "textarea",
"hint" => __("Best Practice: A concise and engaging description for your page or post, optimized for sharing on Twitter/X. This description will appear in the preview when your content is tweeted, providing a brief summary that encourages users to click and interact.
The AI aims to generate a Twitter/X description with an optimal length of 55 to 65 characters.
The Twitter/X description is added to the twitter:description tag of your website.", "ai-for-seo"),
"api-identifier" => "meta_twitter_description",
"output-tag-type" => "meta name",
"output-tag-identifier" => "twitter:description",
"meta-tag-regex" => '/]*name=(["\'])twitter:description\1[^>]*content=(["\'])(.*?)\2[^>]*>/i',
"meta-tag-regex-match-index" => 3,
"flat-credits-cost" => 1,
),
));
define ('AI4SEO_ATTACHMENT_ATTRIBUTES_DETAILS', array(
"title" => array(
"name" => esc_html__("Title", "ai-for-seo"),
"icon" => "headline",
"mime-type-restrictions" => array(),
"input-type" => "textarea",
"hint" => __("Best Practice: A descriptive and unique title for your image that helps users and search engines understand the content of the image. This title is displayed when the image is loaded in the browser and may be used as the default filename if someone downloads the image.
The AI aims to generate an image title with an optimal length of 20 to 50 characters.
The image title is not directly visible on your website but is stored in the image metadata. A well-crafted title can aid in organizing your media library and improve searchability within WordPress.", "ai-for-seo"),
"api-identifier" => "image_title",
"flat-credits-cost" => 1,
),
"alt-text" => array(
"name" => esc_html__("Alt Text", "ai-for-seo"),
"icon" => "code",
"mime-type-restrictions" => array(
"image/jpeg",
"image/gif",
"image/png",
"image/bmp",
"image/tiff",
"image/webp",
"image/avif",
"image/x-icon",
"image/heic",
),
"input-type" => "textarea",
"hint" => __("Best Practice: An informative and clear alt text for your image that describes its content and function. This text is used by screen readers to assist visually impaired users and is displayed in place of the image if it cannot be loaded. It also contributes to SEO by providing context to search engines.
The AI aims to generate alt text with an optimal length of 145 to 155 characters.
Alt text is added to the alt attribute of the image HTML tag.", "ai-for-seo"),
"api-identifier" => "image_alt_text",
"flat-credits-cost" => 2,
),
"caption" => array(
"name" => esc_html__("Caption", "ai-for-seo"),
"icon" => "subtitle",
"mime-type-restrictions" => array(),
"input-type" => "textarea",
"hint" => __("Best Practice: A brief and engaging caption for your image that provides additional context or credit information. Captions are typically displayed below the image on your website and can help enhance user engagement and provide useful information.
The AI aims to generate a caption with an optimal length of 50 to 125 characters.
The caption is added to the caption field in the WordPress Media Library and is displayed directly on the page where the image appears.", "ai-for-seo"),
"api-identifier" => "image_caption",
"flat-credits-cost" => 1,
),
"description" => array(
"name" => esc_html__("Description", "ai-for-seo"),
"icon" => "subtitles",
"mime-type-restrictions" => array(),
"input-type" => "textarea",
"hint" => __("Best Practice: A detailed and informative description of your image, which helps users understand the image's content and context. This description is particularly useful for internal reference and can aid in organizing and managing your media library.
The AI aims to generate a description with an optimal length of 155 to 165 characters.
The description is stored in the image metadata and is not directly visible to users on your website. A well-crafted description can aid in organizing your media library and improve searchability within WordPress.", "ai-for-seo"),
"api-identifier" => "image_description",
"flat-credits-cost" => 1,
),
#"file-name" => array(
# "name" => esc_html__("File Name", "ai-for-seo"),
# "mime-type-restrictions" => array(),
# "input-type" => "textfield",
# "hint" => __("The AI will generate a file name for your image based on its content. A descriptive file name can improve SEO and help search engines understand the image. Review the file name to ensure it accurately reflects the image.", "ai-for-seo"),
# "api-identifier" => "image_file_name",
# "flat-credits-cost" => 2,
#),
));
define('AI4SEO_TRANSLATED_LANGUAGE_NAMES', array(
"en" => __("English", "ai-for-seo"),
"de" => __("German", "ai-for-seo"),
"fr" => __("French", "ai-for-seo"),
"es" => __("Spanish", "ai-for-seo"),
"it" => __("Italian", "ai-for-seo"),
"nl" => __("Dutch", "ai-for-seo"),
"pt" => __("Portuguese", "ai-for-seo"),
"ru" => __("Russian", "ai-for-seo"),
"zh" => __("Chinese", "ai-for-seo"),
"ja" => __("Japanese", "ai-for-seo"),
"ko" => __("Korean", "ai-for-seo"),
));
}, 7);
function ai4seo_get_allowed_html_tags_and_attributes(): array {
static $ai4seo_allowed_html_tags_and_attributes = array(
"div" => array(
"id" => array(),
"class" => array(),
"onclick" => array(),
"style" => array(),
"title" => array(),
),
"img" => array(
"class" => array(),
"src" => array(),
"alt" => array(),
"onclick" => array(),
"style" => array(),
),
'meta' => array(
'name' => array(),
'content' => array(),
'property' => array(),
),
'title' => array(),
'svg' => array(
'viewbox' => array(),
'aria-label' => array(),
'class' => array(),
'xmlns' => array(),
),
'rect' => array(
'width' => array(),
'height' => array(),
'rx' => array(),
'ry' => array(),
'x' => array(),
'y' => array(),
'fill' => array(),
),
'line' => array(
'x1' => array(),
'y1' => array(),
'x2' => array(),
'y2' => array(),
'stroke' => array(),
'stroke-width' => array(),
),
'defs' => array(),
'style' => array(),
'path' => array(
'class' => array(),
'd' => array(),
'fill-rule' => array(),
'fill' => array(),
'clip-rule' => array(),
),
'g' => array(
'class' => array(),
),
'circle' => array(
'cx' => array(),
'cy' => array(),
'r' => array(),
'fill' => array(),
),
'polygon' => array(
'points' => array(),
'fill' => array(),
),
'text' => array(
'x' => array(),
'y' => array(),
'font-size' => array(),
'font-family' => array(),
'font-weight' => array(),
'fill' => array(),
),
"button" => array(
"type" => array(),
"onclick" => array(),
"class" => array(),
"id" => array(),
"disabled" => array(),
"style" => array(),
"data-clipboard-text" => array(),
"data-time-left" => array(),
"aria-controls" => array(),
"aria-expanded" => array(),
),
"span" => array(
"id" => array(),
"class" => array(),
"style" => array(),
"data-trigger" => array(),
"data-time-left" => array(),
"onclick" => array(),
),
"h1" => array(
"class" => array(),
"style" => array(),
),
"h2" => array(
"class" => array(),
"style" => array(),
),
"p" => array(
"class" => array(),
"style" => array(),
),
"b" => array(),
"u" => array(),
"a" => array(
"href" => array(),
"target" => array(),
"rel" => array(),
"title" => array(),
"class" => array(),
"onclick" => array(),
"data-time-left" => array(),
),
"i" => array(
"onclick" => array(),
"class" => array(),
"id" => array(),
"style" => array(),
),
"select" => array(
"id" => array(),
"class" => array(),
"style" => array(),
"onchange" => array(),
),
"option" => array(
"value" => array(),
"selected" => array(),
),
"br" => array(),
"strong" => array(
"class" => array(),
),
"input" => array(
"type" => array(),
"id" => array(),
"class" => array(),
"style" => array(),
"value" => array(),
"name" => array(),
"placeholder" => array(),
"onchange" => array(),
"onclick" => array(),
"disabled" => array(),
"data-target" => array(),
),
"textarea" => array(
"id" => array(),
"class" => array(),
"style" => array(),
"onchange" => array(),
"onclick" => array(),
"disabled" => array(),
),
"label" => array(
"for" => array(),
"class" => array(),
"style" => array(),
),
"center" => array(),
"ol" => array(
"class" => array(),
"style" => array(),
),
"ul" => array(
"class" => array(),
"style" => array(),
),
"li" => array(
"class" => array(),
"style" => array(),
),
"em" => array(),
);
return $ai4seo_allowed_html_tags_and_attributes;
}
$ai4seo_cached_active_plugins_and_themes = array();
$ai4seo_cached_supported_post_types = array();
$ai4seo_checked_supported_post_types = array();
$ai4seo_allowed_attachment_mime_types = array("image/jpeg", "image/png", "image/gif", "image/webp", "image/avif"); # IMPORTANT! Also apply changes to the api-service AND to ai4seo_supported_mime_types-variable in JS-file
$ai4seo_allowed_image_mime_types = array("image/jpeg", "image/png", "image/gif", "image/webp", "image/avif");
$ai4seo_allowed_image_file_type_names = array("jpg", "jpeg", "png", "gif", "webp", "avif");
// Define the constants for full and base language code mappings
const AI4SEO_FULL_LANGUAGE_CODE_MAPPING = array(
'zh_cn' => 'simplified chinese',
'zh_tw' => 'traditional chinese',
'pt_br' => 'brazilian portuguese',
'pt_pt' => 'european portuguese',
'fr_ca' => 'canadian french',
'en_us' => 'american english',
'en_gb' => 'british english',
);
const AI4SEO_BASE_LANGUAGE_CODE_MAPPING = array(
'sq' => 'albanian',
'ar' => 'arabic',
'bg' => 'bulgarian',
'zh' => 'chinese', // General Chinese fallback
'hr' => 'croatian',
'cs' => 'czech',
'da' => 'danish',
'nl' => 'dutch',
'en' => 'english', // General English fallback
'et' => 'estonian',
'fi' => 'finnish',
'fr' => 'french', // General French fallback
'de' => 'german',
'el' => 'greek',
'he' => 'hebrew',
'hi' => 'hindi',
'hu' => 'hungarian',
'is' => 'icelandic',
'id' => 'indonesian',
'it' => 'italian',
'ja' => 'japanese',
'ko' => 'korean',
'lv' => 'latvian',
'lt' => 'lithuanian',
'mk' => 'macedonian',
'mt' => 'maltese',
'no' => 'norwegian',
'pl' => 'polish',
'pt' => 'portuguese', // General Portuguese fallback
'ro' => 'romanian',
'ru' => 'russian',
'sr' => 'serbian',
'sk' => 'slovak',
'sl' => 'slovenian',
'es' => 'spanish', // General Spanish fallback
'sv' => 'swedish',
'th' => 'thai',
'tr' => 'turkish',
'uk' => 'ukrainian',
'vi' => 'vietnamese',
);
// allowed ajax function (also change in javascript file)
const AI4SEO_ALLOWED_AJAX_FUNCTIONS = array(
"ai4seo_save_anything",
"ai4seo_show_metadata_editor",
"ai4seo_show_attachment_attributes_editor",
"ai4seo_generate_metadata",
"ai4seo_generate_attachment_attributes",
"ai4seo_reject_tos",
"ai4seo_accept_tos",
"ai4seo_show_terms_of_service",
"ai4seo_dismiss_notification",
"ai4seo_get_dashboard_html",
"ai4seo_reset_plugin_data",
"ai4seo_stop_bulk_generation",
"ai4seo_retry_all_failed_attachment_attributes",
"ai4seo_retry_all_failed_metadata",
"ai4seo_disable_payg",
"ai4seo_init_purchase",
"ai4seo_track_subscription_pricing_visit",
"ai4seo_import_nextgen_gallery_images",
"ai4seo_export_settings",
"ai4seo_show_import_settings_preview",
"ai4seo_import_settings",
"ai4seo_restore_default_settings",
"ai4seo_request_lost_licence_data",
"ai4seo_refresh_dashboard_statistics",
"ai4seo_refresh_robhub_account",
);
// the robhub api communicator is used to communicate with the robhub api which handles all the ai stuff
$ai4seo_robhub_api = null;
$ai4seo_are_settings_currently_being_initialized = false;
$ai4seo_are_settings_initialized = false;
// ___________________________________________________________________________________________ \\
// === INITIALIZATION ======================================================================== \\
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ \\
// init settings
add_action("init", "ai4seo_init_settings", 8);
// CRON CALL ONLY
if (wp_doing_cron()) {
// init cron jobs
add_action("init", "ai4seo_init_robhub_api", 9);
add_action("init", "ai4seo_init_cron_jobs", 10);
// exit here
return;
}
// FOR FRONTEND, LOGGED-OUT USERS. ALSO FOR: LOGGED-IN USERS, ADMIN AREA
// init plugin injections for all users for the frontend
add_action("init", "ai4seo_enqueue_frontend_scripts");
add_action("init", "ai4seo_init_frontend_injections");
// FOR LOGGED-IN USERS. ALSO FOR: ADMIN AREA
// init (logged-in) user essentials after all plugins have been loaded, used for admin area and frontend
add_action("init", "ai4seo_init_user_essentials");
// perform ajax nonce check
add_action( 'admin_init', 'ai4seo_ajax_nonce_check', 9999 );
// not admin area -> exit here
if (!ai4seo_is_function_usable("is_admin") || !is_admin()) {
return;
}
// init admin essentials for the backend after all plugins have been loaded
add_action("init", "ai4seo_init_admin_area_essentials", 12);
// on plugin deactivation
register_deactivation_hook(__FILE__, "ai4seo_on_deactivation");
if (ai4seo_does_user_need_to_accept_tos_toc_and_pp()) {
return;
}
// init cron jobs
add_action("init", "ai4seo_init_cron_jobs");
// do some checks after all plugins have been loaded
add_action('init', 'ai4seo_check_and_handle_plugin_update');
// check for unfinished post table analysis
add_action('init', 'ai4seo_try_start_posts_table_analysis', 9);
// check for new notifications
add_action('init', 'ai4seo_check_for_new_notifications', 13);
// init admin essentials for the backend after all plugins have been loaded
add_action("init", "ai4seo_send_additional_tos_accept_details");
// on saving a post, check if the all ceo meta tags are filled
add_action("save_post", "ai4seo_mark_post_to_be_analyzed", 20, 3);
// analyze the post after it has been saved, call ai4seo_handle_posts_to_be_analyzed() at the end of the request
add_action("shutdown", "ai4seo_handle_posts_to_be_analyzed");
// on plugin activation
register_activation_hook(__FILE__, "ai4seo_on_activation");
// === INIT FUNCTIONS ======================================================================== \\
/**
* Function to init plugin injections for all users for the frontend
* @return void
*/
function ai4seo_init_frontend_injections() {
if (!ai4seo_singleton(__FUNCTION__)) {
return;
}
// make sure we are on the frontend and not in the admin area, also exclude feeds, REST requests and AJAX requests
if (
is_admin()
|| is_feed()
|| ( defined( 'REST_REQUEST' ) && REST_REQUEST )
|| ( defined( 'DOING_AJAX' ) && DOING_AJAX )
) {
return;
}
// workaround for Squirrly SEO, as they use their own buffer
$is_squirrly_seo_active = ai4seo_is_plugin_or_theme_active(AI4SEO_THIRD_PARTY_PLUGIN_SQUIRRLY_SEO);
if ($is_squirrly_seo_active) {
// Squirrly SEO workaround, as they use their own buffer
add_action("sq_buffer", "ai4seo_inject_our_meta_tags_into_the_html_head", 20);
add_action("sq_buffer", "ai4seo_inject_image_attributes_into_html", 20);
return;
}
// inject meta tags and image attributes into html
add_action( 'template_redirect', function(){
ob_start( function( $html ) {
$html = ai4seo_inject_our_meta_tags_into_the_html_head( $html );
return ai4seo_inject_image_attributes_into_html( $html );
} );
}, PHP_INT_MAX );
add_action( 'shutdown', function(){
if ( ob_get_length() ) {
echo ob_get_clean();
}
} );
/*
// add alt text injection to images (for logged-in users and guests)
add_filter("the_content", "ai4seo_inject_image_attributes", 99999);
// also filter block output for gutenberg blocks to inject alt text
add_filter("render_block", "ai4seo_inject_image_attributes_for_gutenberg", 99999, 2);
// Also cover images output via wp_get_attachment_image() and similar.
add_filter('wp_get_attachment_image_attributes', 'ai4seo_filter_wp_image_attrs', 10, 3);
add_filter( 'post_thumbnail_html', 'ai4seo_inject_image_attributes', 99999, 5 );
add_filter( 'wp_get_attachment_image_attributes', 'ai4seo_inject_image_attributes', 99999, 3 );
add_filter( 'get_image_tag', 'ai4seo_inject_image_attributes', 99999, 6 );
add_filter( 'get_avatar', 'ai4seo_inject_image_attributes', 99999, 6 );
add_filter( 'widget_text', 'ai4seo_inject_image_attributes', 99999 );
add_filter( 'the_excerpt', 'ai4seo_inject_image_attributes', 99999 );
add_filter( 'get_the_excerpt', 'ai4seo_inject_image_attributes', 99999 );
*/
}
// =========================================================================================== \\
/**
* Function to init plugin essentials for admins in the front and backend
* @return void
*/
function ai4seo_init_user_essentials() {
// Make sure that the user is allowed to use this plugin
if (!ai4seo_can_manage_this_plugin()) {
return;
}
// enqueue scripts and styles
add_action('wp_enqueue_scripts', 'ai4seo_enqueue_admin_scripts');
add_action('admin_enqueue_scripts', 'ai4seo_enqueue_admin_scripts');
// init ajax functions
foreach (AI4SEO_ALLOWED_AJAX_FUNCTIONS AS $this_ajax_function) {
add_action("wp_ajax_{$this_ajax_function}", $this_ajax_function);
}
// add modal schemas to the footer
add_action("wp_footer", "ai4seo_include_modal_schemas_file");
add_action("get_footer", "ai4seo_include_modal_schemas_file");
add_action("admin_footer", "ai4seo_include_modal_schemas_file");
// register compatibility with other plugins
if (ai4seo_is_plugin_or_theme_active(AI4SEO_THIRD_PARTY_PLUGIN_NEXTGEN_GALLERY)) {
register_post_type( AI4SEO_NEXTGEN_GALLERY_POST_TYPE, array(
'label' => AI4SEO_NEXTGEN_GALLERY_POST_TYPE,
'public' => false,
'show_ui' => false,
'show_in_menu' => false,
'exclude_from_search' => true,
'publicly_queryable' => false,
'query_var' => false,
'rewrite' => false,
'capability_type' => 'post',
'supports' => array( 'title', 'editor' ),
'can_export' => false,
'show_in_rest' => false,
) );
}
// user needs to accept tos? stop here, to prevent further plugin actions
if (ai4seo_does_user_need_to_accept_tos_toc_and_pp()) {
return;
}
// admin bar menu item
add_action("admin_bar_menu", "ai4seo_add_admin_menu_item", 999);
}
// =========================================================================================== \\
/**
* Function to init plugin essentials for admins in the backend
* @return void
*/
function ai4seo_init_admin_area_essentials() {
// ADMIN AREA ONLY (REST OF INIT CODE FROM HERE) ->
// make sure the robhub api communicator is initialized before anything else
if (!ai4seo_init_robhub_api()) {
// if the robhub api communicator could not be initialized, we cannot continue
// show notice
add_action('admin_notices', function() {
echo '
' . esc_html__("The AI for SEO plugin could not be initialized. Class 'Ai4Seo_RobHubApiCommunicator' could not be initialized. Please check your server configuration and try again.", "ai-for-seo") . '
';
});
// exit here
return;
}
// Overwrite the plugin-details for white-label-settings
add_filter("all_plugins", "ai4seo_modify_plugin_details_for_white_label", 10, 1);
// Make sure that the user is allowed to use this plugin
if (!ai4seo_can_manage_this_plugin()) {
return;
}
$is_user_inside_our_plugin_admin_pages = ai4seo_is_user_inside_our_plugin_admin_pages();
// Add menu-item to main menu, sub menu-items and page titles
add_filter('admin_title', 'ai4seo_filter_admin_title', 10, 2 );
add_action('admin_menu', "ai4seo_add_menu_entries");
add_filter('parent_file', 'ai4seo_mark_parent_menu_active');
add_filter('submenu_file', 'ai4seo_mark_submenu_active');
// plugin action link use filter "plugin_action_links_ + plugin_basename"
$this_plugin_basename = sanitize_text_field(ai4seo_get_plugin_basename());
add_filter("plugin_action_links_{$this_plugin_basename}", 'ai4seo_add_links_to_the_plugin_directory', 999);
// show terms of service if not accepted yet
$last_tos_modal_open_time = (int) ai4seo_read_environmental_variable(AI4SEO_ENVIRONMENTAL_VARIABLE_TOS_LAST_MODAL_OPEN_TIME);
// outside the plugin admin pages, show the modal only once a week
if ($is_user_inside_our_plugin_admin_pages || $last_tos_modal_open_time < time() - WEEK_IN_SECONDS) {
if (ai4seo_does_user_need_to_accept_tos_toc_and_pp()) {
add_action("wp_footer", "ai4seo_show_terms_of_service_modal");
add_action("get_footer", "ai4seo_show_terms_of_service_modal");
add_action("admin_footer", "ai4seo_show_terms_of_service_modal");
}
}
if (ai4seo_does_user_need_to_accept_tos_toc_and_pp()) {
// stop here, to prevent further plugin actions
return;
}
// put our code into the post and page table
add_filter("manage_post_posts_columns", "ai4seo_add_metadata_editor_column_to_posts_table");
add_filter("manage_page_posts_columns", "ai4seo_add_metadata_editor_column_to_posts_table");
#add_filter("manage_edit-product_columns", "ai4seo_add_metadata_editor_column_to_posts_table");
add_action("manage_post_posts_custom_column", "ai4seo_add_metadata_editor_button_to_posts_table", 10, 2);
add_action("manage_page_posts_custom_column", "ai4seo_add_metadata_editor_button_to_posts_table", 10, 2);
#add_action("manage_product_posts_custom_column", "ai4seo_add_metadata_editor_button_to_posts_table", 10, 2);
// add ajax nonce field to the footer
add_action( 'admin_print_footer_scripts', 'ai4seo_print_ajax_nonce_field' );
// if user is inside our plugin admin pages, check for account sync
if ($is_user_inside_our_plugin_admin_pages) {
ai4seo_check_for_robhub_account_sync();
}
}
// === FUNCTION TO INIT AI4SEO-PLUGIN-SETTINGS =============================================== \\
/**
* Function to init the plugin-settings
* @return void
*/
function ai4seo_init_settings() {
global $ai4seo_settings;
global $ai4seo_are_settings_initialized;
global $ai4seo_are_settings_currently_being_initialized;
// Make sure that settings are only initialized once
if ($ai4seo_are_settings_initialized) {
return;
}
if ($ai4seo_are_settings_currently_being_initialized) {
error_log("AI4SEO Init Settings: Settings are already being initialized. Exiting to prevent recursion.");
//error_log(__FUNCTION__ . "() @ " . __LINE__ . ": " . print_r("AI4SEO Init Settings: Settings are already being initialized. Exiting to prevent recursion.", true) . "\r\n\r\nBACKTRACE\r\n " . ai4seo_get_backtrace_debug_message("\r\n") . "\r\n\r\n");
return;
}
$ai4seo_are_settings_currently_being_initialized = true;
try {
// Read settings from database
$from_database_settings = ai4seo_read_settings();
// Loop through settings and add the new values to $ai4seo_settings
foreach ($from_database_settings as $setting_name => $setting_value) {
// Make sure that this setting is valid
if (!ai4seo_validate_setting_value($setting_name, $setting_value)) {
continue;
}
// Save the new values to $ai4seo_settings
$ai4seo_settings[$setting_name] = $setting_value;
}
$ai4seo_are_settings_currently_being_initialized = false;
$ai4seo_are_settings_initialized = true;
} finally {
$ai4seo_are_settings_currently_being_initialized = false;
}
}
// =========================================================================================== \\
function ai4seo_read_settings() : array {
// Read settings from database
$settings = ai4seo_get_option(AI4SEO_SETTINGS_OPTION_NAME);
// Make sure that settings could be read from database
if (!$settings) {
$settings = array();
}
$settings = maybe_unserialize($settings);
// Make sure that $settings is array
if (!is_array($settings)) {
if (is_string($settings) && ai4seo_is_json($settings)) {
$settings = json_decode($settings, true);
}
}
if (!is_array($settings)) {
$settings = array();
}
$settings = ai4seo_deep_sanitize($settings);
$settings = ai4seo_deep_sanitize($settings, 'ai4seo_wp_unslash');
return $settings;
}
// =========================================================================================== \\
/**
* Things to do on plugin activation
* @return void
*/
function ai4seo_on_activation() {
// set AI4SEO_ENVIRONMENTAL_VARIABLE_PLUGIN_ACTIVATION_TIME
if (!ai4seo_read_environmental_variable(AI4SEO_ENVIRONMENTAL_VARIABLE_PLUGIN_ACTIVATION_TIME)) {
ai4seo_update_environmental_variable(AI4SEO_ENVIRONMENTAL_VARIABLE_PLUGIN_ACTIVATION_TIME, time());
}
// init cron jobs
ai4seo_init_cron_jobs();
}
// =========================================================================================== \\
/**
* Things to do on plugin deactivation
* @return void
*/
function ai4seo_on_deactivation() {
// un schedule all cron jobs
ai4seo_un_schedule_cron_jobs();
ai4seo_robhub_api()->perform_product_deactivated_call();
// Check for function get_current_user_id()
if (!function_exists("get_current_user_id")) {
return;
}
// Define variables for the incognito-setting
$ai4seo_setting_enable_incognito_mode = ai4seo_is_incognito_mode_enabled();
$ai4seo_setting_incognito_mode_user_id = ai4seo_get_setting(AI4SEO_SETTING_INCOGNITO_MODE_USER_ID);
$current_user_id = get_current_user_id();
// Delete plugin if it was deactivated by non-incognito mode user
if ($ai4seo_setting_enable_incognito_mode && $ai4seo_setting_incognito_mode_user_id != AI4SEO_DEFAULT_SETTINGS[AI4SEO_SETTING_INCOGNITO_MODE_USER_ID] && $ai4seo_setting_incognito_mode_user_id != $current_user_id) {
// Make sure we can call delete_plugins()
if (!function_exists("delete_plugins")) {
include_once(ABSPATH . "wp-admin/includes/plugin.php");
}
// Attempt to delete this plugin's files
if (function_exists("delete_plugins")) {
delete_plugins([plugin_basename(__FILE__)]);
}
}
}
// =========================================================================================== \\
function ai4seo_is_incognito_mode_enabled(): bool {
if (isset($_REQUEST["ai4seo_debug_bypass_incognito_mode"]) && $_REQUEST["ai4seo_debug_bypass_incognito_mode"]) {
// If the debug bypass parameter is set, we can bypass the incognito mode
return false;
}
// Check if the incognito mode is enabled
$ai4seo_setting_enable_incognito_mode = ai4seo_get_setting(AI4SEO_SETTING_ENABLE_INCOGNITO_MODE);
// If the incognito mode is enabled, return true
if ($ai4seo_setting_enable_incognito_mode) {
return true;
}
// Otherwise, return false
return false;
}
// =========================================================================================== \\
/**
* Function to check if we have updated recently and do some actions accordingly
* @return void
*/
function ai4seo_check_and_handle_plugin_update() {
$last_known_plugin_version = strval(ai4seo_read_environmental_variable(AI4SEO_ENVIRONMENTAL_VARIABLE_LAST_KNOWN_PLUGIN_VERSION));
// same plugin version as last known version? -> skip
if ($last_known_plugin_version == AI4SEO_PLUGIN_VERSION_NUMBER) {
return;
}
// save new version to database
ai4seo_update_environmental_variable(AI4SEO_ENVIRONMENTAL_VARIABLE_LAST_KNOWN_PLUGIN_VERSION, AI4SEO_PLUGIN_VERSION_NUMBER);
// workaround for version 0.0.0 -> remove $last_known_plugin_version
if ($last_known_plugin_version == AI4SEO_DEFAULT_ENVIRONMENTAL_VARIABLES[AI4SEO_ENVIRONMENTAL_VARIABLE_LAST_KNOWN_PLUGIN_VERSION]) {
$last_known_plugin_version = "";
}
// tidy up some old version parameters, tables and options
ai4seo_tidy_up($last_known_plugin_version);
// call "product-updated" endpoint to RobHub if we are not on a fresh install
if ($last_known_plugin_version) {
// call robhub api endpoint "client/product-updated" with the old and new plugin version
$robhub_api_parameters = array(
"old_version" => $last_known_plugin_version,
"new_version" => AI4SEO_PLUGIN_VERSION_NUMBER,
);
ai4seo_robhub_api()->call("client/product-updated", $robhub_api_parameters);
// maybe push a new plugin update notification
ai4seo_check_for_plugin_update_notification($last_known_plugin_version, true);
}
}
// =========================================================================================== \\
/**
* Function to clean up old version's options, variables etc. Clean-up. Clean_up, Tidy-up
* @param $last_known_plugin_version string The last known plugin version, used to determine which cleanup actions to perform
* @return void
*/
function ai4seo_tidy_up(string $last_known_plugin_version = AI4SEO_PLUGIN_VERSION_NUMBER) {
// reestablish cron jobs
ai4seo_un_schedule_cron_jobs();
ai4seo_init_cron_jobs();
// start cron jobs in 10 seconds
ai4seo_inject_additional_cronjob_call(AI4SEO_BULK_GENERATION_CRON_JOB_NAME, 10);
ai4seo_inject_additional_cronjob_call(AI4SEO_ANALYSE_PLUGIN_PERFORMANCE_CRON_JOB_NAME, 10);
// unset temporary environmental variables
ai4seo_robhub_api()->reset_last_account_sync();
ai4seo_robhub_api()->tidy_up_api_locks();
ai4seo_update_environmental_variable(AI4SEO_ENVIRONMENTAL_VARIABLE_LAST_CRON_JOB_CALL, time() - 300);
ai4seo_update_environmental_variable(AI4SEO_ENVIRONMENTAL_VARIABLE_LAST_SPECIFIC_CRON_JOB_CALLS, array());
// we need the raw settings to check for old variations of the settings
$raw_settings = ai4seo_read_settings();
// we need the raw environmental variables to check for old variations
$raw_environmental_variables = ai4seo_get_option(AI4SEO_ENVIRONMENTAL_VARIABLES_OPTION_NAME);
if($raw_environmental_variables) {
$raw_environmental_variables = maybe_unserialize($raw_environmental_variables);
$raw_environmental_variables = ai4seo_deep_sanitize($raw_environmental_variables);
}
// === V1.1.X ================================================================================= \\
// remove old options (from older versions)
// required after V1.1.1
if ($last_known_plugin_version && version_compare($last_known_plugin_version, '1.1.1', '<')) {
ai4seo_delete_option("_ai4seo_current_credits_balance");
}
// if old option ai4seo_missing_seo_data_post_ids is set, rename it to ai4seo_processing_metadata_post_ids
// required after V1.1.2
if ($last_known_plugin_version && version_compare($last_known_plugin_version, '1.1.2', '<')) {
if (ai4seo_get_option("ai4seo_missing_seo_data_post_ids")) {
$missing_seo_data_post_ids = ai4seo_get_option("ai4seo_missing_seo_data_post_ids");
ai4seo_update_option("ai4seo_processing_metadata_post_ids", $missing_seo_data_post_ids);
ai4seo_delete_option("ai4seo_missing_seo_data_post_ids");
}
// if old option _ai4seo_num_existing_going_to_fill_this_post_ids_by_post_type is set, rename it to _ai4seo_num_processing_metadata_post_ids_by_post_type
// required after V1.1.2
if (ai4seo_get_option("_ai4seo_num_existing_going_to_fill_this_post_ids_by_post_type")) {
$num_existing_going_to_fill_this_post_ids_by_post_type = ai4seo_get_option("_ai4seo_num_existing_going_to_fill_this_post_ids_by_post_type");
ai4seo_update_option("_ai4seo_num_processing_metadata_post_ids_by_post_type", $num_existing_going_to_fill_this_post_ids_by_post_type);
ai4seo_delete_option("_ai4seo_num_existing_going_to_fill_this_post_ids_by_post_type");
}
// clear schedule of old cronjobs, as of V1.1.2 we use new cronjobs
wp_clear_scheduled_hook("ai4seo_search_missing_seo_data_posts");
wp_clear_scheduled_hook("ai4seo_search_missing_metadata_posts");
wp_clear_scheduled_hook("ai4seo_automated_seo_data_generation");
}
// V1.1.8: clear schedule of old cronjob "ai4seo_automated_metadata_generation", it's now called "ai4seo_automated_generation_cron_job"
if ($last_known_plugin_version && version_compare($last_known_plugin_version, '1.1.8', '<')) {
wp_clear_scheduled_hook("ai4seo_automated_metadata_generation");
ai4seo_delete_option("ai4seo_is_automation_activated_for_posts");
ai4seo_delete_option("ai4seo_is_automation_activated_for_pages");
ai4seo_delete_option("ai4seo_is_automation_activated_for_products");
}
// === V1.2.X ================================================================================= \\
// if old option ai4seo_already_filled_post_ids is set, rename it to ai4seo_already_filled_metadata_post_ids
// required after V1.2
if ($last_known_plugin_version && version_compare($last_known_plugin_version, '1.2', '<')) {
if (ai4seo_get_option("ai4seo_already_filled_post_ids")) {
$already_filled_metadata_post_ids = ai4seo_get_option("ai4seo_already_filled_post_ids");
ai4seo_update_option("ai4seo_already_filled_metadata_post_ids", $already_filled_metadata_post_ids);
ai4seo_delete_option("ai4seo_already_filled_post_ids");
}
// if old option ai4seo_failed_to_fill_post_ids is set, rename it to ai4seo_failed_to_fill_metadata_post_ids
// required after V1.2
if (ai4seo_get_option("ai4seo_failed_to_fill_post_ids")) {
$failed_to_fill_metadata_post_ids = ai4seo_get_option("ai4seo_failed_to_fill_post_ids");
ai4seo_update_option("ai4seo_failed_to_fill_metadata_post_ids", $failed_to_fill_metadata_post_ids);
ai4seo_delete_option("ai4seo_failed_to_fill_post_ids");
}
// V1.2: check for table "wp_ai4seo_cache" (id, post_id, data), if available, save all it's "data" to the post_meta of the corresponding post_id, using ai4seo_save_generated_data()
ai4seo_tidy_up_old_ai4seo_cache_table();
}
// V1.2.1: Delete old summary options
if ($last_known_plugin_version && version_compare($last_known_plugin_version, '1.2.1', '<')) {
if (ai4seo_get_option("_ai4seo_num_processing_metadata_post_ids_by_post_type")) {
ai4seo_delete_option("_ai4seo_num_processing_metadata_post_ids_by_post_type");
}
if (ai4seo_get_option("_ai4seo_num_failed_to_fill_post_ids_by_post_type")) {
ai4seo_delete_option("_ai4seo_num_failed_to_fill_post_ids_by_post_type");
}
if (ai4seo_get_option("_ai4seo_num_already_filled_post_ids_by_post_type")) {
ai4seo_delete_option("_ai4seo_num_already_filled_post_ids_by_post_type");
}
if (ai4seo_get_option("_ai4seo_num_posts_not_filled_by_post_type")) {
ai4seo_delete_option("_ai4seo_num_posts_not_filled_by_post_type");
}
if (ai4seo_get_option("ai4seo_already_filled_metadata_post_ids")) {
ai4seo_delete_option("ai4seo_already_filled_metadata_post_ids");
}
if (ai4seo_get_option("ai4seo_already_filled_attributes_attachment_post_ids")) {
ai4seo_delete_option("ai4seo_already_filled_attributes_attachment_post_ids");
}
// V1.2.1: Rename some post ids options
// (ai4seo_failed_to_fill_metadata_post_ids -> ai4seo_failed_metadata_post_ids)
// (ai4seo_failed_to_fill_attributes_attachment_post_ids -> ai4seo_failed_attributes_attachment_post_ids)
if (ai4seo_get_option("ai4seo_failed_to_fill_metadata_post_ids")) {
$failed_metadata_post_ids = ai4seo_get_option("ai4seo_failed_to_fill_metadata_post_ids");
ai4seo_update_option("ai4seo_failed_metadata_post_ids", $failed_metadata_post_ids);
ai4seo_delete_option("ai4seo_failed_to_fill_metadata_post_ids");
}
if (ai4seo_get_option("ai4seo_failed_to_fill_attributes_attachment_post_ids")) {
$failed_attributes_attachment_post_ids = ai4seo_get_option("ai4seo_failed_to_fill_attributes_attachment_post_ids");
ai4seo_update_option("ai4seo_failed_attributes_attachment_post_ids", $failed_attributes_attachment_post_ids);
ai4seo_delete_option("ai4seo_failed_to_fill_attributes_attachment_post_ids");
}
}
// V1.2.6: Save various options into the new environmental variables option
if ($last_known_plugin_version && version_compare($last_known_plugin_version, '1.2.6', '<')) {
if (ai4seo_get_option("_ai4seo_robhub_last_credit_balance_check") !== false) {
ai4seo_delete_option("_ai4seo_robhub_last_credit_balance_check");
}
if (ai4seo_get_option("ai4seo_robhub_auth_data") !== false) {
$old_robhub_auth_data = ai4seo_get_option("ai4seo_robhub_auth_data");
$old_api_username = sanitize_text_field($old_robhub_auth_data[0] ?? "");
$old_api_password = sanitize_text_field($old_robhub_auth_data[1] ?? "");
ai4seo_robhub_api()->update_environmental_variable(ai4seo_robhub_api()::ENVIRONMENTAL_VARIABLE_API_USERNAME, $old_api_username);
ai4seo_robhub_api()->update_environmental_variable(ai4seo_robhub_api()::ENVIRONMENTAL_VARIABLE_API_PASSWORD, $old_api_password);
ai4seo_delete_option("ai4seo_robhub_auth_data");
}
if (ai4seo_get_option("_ai4seo_robhub_credits_balance") !== false) {
ai4seo_robhub_api()->update_environmental_variable(ai4seo_robhub_api()::ENVIRONMENTAL_VARIABLE_CREDITS_BALANCE, (int) ai4seo_get_option("_ai4seo_robhub_credits_balance"));
ai4seo_delete_option("_ai4seo_robhub_credits_balance");
}
if (ai4seo_get_option("_ai4seo_version") !== false) {
ai4seo_update_environmental_variable(AI4SEO_ENVIRONMENTAL_VARIABLE_LAST_KNOWN_PLUGIN_VERSION, ai4seo_get_option("_ai4seo_version"));
ai4seo_delete_option("_ai4seo_version");
}
if (ai4seo_get_option("_ai4seo_licence_key_shown") !== false) {
#ai4seo_update_environmental_variable(AI4SEO_ENVIRONMENTAL_VARIABLE_LICENSE_KEY_SHOWN, (bool) ai4seo_get_option("_ai4seo_licence_key_shown"));
ai4seo_delete_option("_ai4seo_licence_key_shown");
}
if (ai4seo_get_option("_ai4seo_last_cronjob_call") !== false) {
# we defined the new variable earlier in this function, therefore we can safely delete the old one
ai4seo_delete_option("_ai4seo_last_cronjob_call");
}
if (ai4seo_get_option("_ai4seo_last_cronjob_call_for_ai4seo_automated_generation_cron_job") !== false) {
# we defined the new variable earlier in this function, therefore we can safely delete the old one
ai4seo_delete_option("_ai4seo_last_cronjob_call_for_ai4seo_automated_generation_cron_job");
}
if (ai4seo_get_option("_ai4seo_last_cronjob_call_for_ai4seo_automated_metadata_generation") !== false) {
# we defined the new variable earlier in this function, therefore we can safely delete the old one
ai4seo_delete_option("_ai4seo_last_cronjob_call_for_ai4seo_automated_metadata_generation");
}
if (ai4seo_get_option("_ai4seo_performance_notice_dismissed_timestamp") !== false) {
# we defined the new variable earlier in this function, therefore we can safely delete the old one
ai4seo_delete_option("_ai4seo_performance_notice_dismissed_timestamp");
}
}
// === V2.0.X ================================================================================= \\
// V2.0.0:
// robhub auth data changed from environmental variable "auth_data" to "api_username" and "api_password"
if ($last_known_plugin_version && version_compare($last_known_plugin_version, '2.0.0', '<')) {
ai4seo_robhub_api()->tidy_up_deprecated_auth_data();
// V2.0.0: Settings migration
// enabled_automated_generations -> enabled_bulk_generation_post_types
if (isset($raw_settings['enabled_automated_generations']) && is_array($raw_settings['enabled_automated_generations'])) {
$new_enabled_bulk_generation_post_types = array();
foreach ($raw_settings['enabled_automated_generations'] AS $this_post_type => $this_is_enabled) {
if ($this_is_enabled) {
$new_enabled_bulk_generation_post_types[] = $this_post_type;
}
}
if ($new_enabled_bulk_generation_post_types) {
ai4seo_update_setting(AI4SEO_SETTING_ENABLED_BULK_GENERATION_POST_TYPES, $new_enabled_bulk_generation_post_types);
}
}
// automated_generation_order (array) -> bulk_generation_order (string)
if (isset($raw_settings['automated_generation_order']) && is_array($raw_settings['automated_generation_order'])) {
// get first element of the array, set it as the new value
if (count($raw_settings['automated_generation_order']) >= 1) {
$new_bulk_generation_order = reset($raw_settings['automated_generation_order']);
if ($new_bulk_generation_order) {
ai4seo_update_setting(AI4SEO_SETTING_BULK_GENERATION_ORDER, $new_bulk_generation_order);
}
}
}
// automated_generation_new_or_existing_filter (array) -> bulk_generation_new_or_existing_filter (string)
if (isset($raw_settings['automated_generation_new_or_existing_filter']) && is_array($raw_settings['automated_generation_new_or_existing_filter'])) {
// get first element of the array, set it as the new value
if (count($raw_settings['automated_generation_new_or_existing_filter']) >= 1) {
$new_bulk_generation_new_or_existing_filter = reset($raw_settings['automated_generation_new_or_existing_filter']);
if ($new_bulk_generation_new_or_existing_filter) {
ai4seo_update_setting(AI4SEO_SETTING_BULK_GENERATION_NEW_OR_EXISTING_FILTER, $new_bulk_generation_new_or_existing_filter);
}
}
}
// automated_generation_new_or_existing_filter_reference_times (array) -> bulk_generation_new_or_existing_filter_reference_time (string)
// environmental variable
if (isset($raw_environmental_variables['automated_generation_new_or_existing_filter_reference_times']) && is_array($raw_environmental_variables['automated_generation_new_or_existing_filter_reference_times'])) {
// get first element of the array, set it as the new value
if (count($raw_environmental_variables['automated_generation_new_or_existing_filter_reference_times']) >= 1) {
$new_bulk_generation_new_or_existing_filter_reference_time = reset($raw_environmental_variables['automated_generation_new_or_existing_filter_reference_times']);
if ($new_bulk_generation_new_or_existing_filter_reference_time) {
ai4seo_update_environmental_variable(AI4SEO_ENVIRONMENTAL_VARIABLE_BULK_GENERATION_NEW_OR_EXISTING_FILTER_REFERENCE_TIME, $new_bulk_generation_new_or_existing_filter_reference_time);
}
}
}
}
// === 2.1.X ================================================================================= \\
// V2.1.0:
if ($last_known_plugin_version && version_compare($last_known_plugin_version, '2.1.0', '<')) {
// Remove old environmental variable "performance_notice_dismissed_time" and dismissed_one_time_notices, feature was removed in V2.1.0
ai4seo_delete_environmental_variable("performance_notice_dismissed_time");
ai4seo_delete_environmental_variable("dismissed_one_time_notices");
ai4seo_delete_environmental_variable("is_first_purchase_discount_available");
ai4seo_delete_environmental_variable("early_bird_discount_time_left");
// delete option "_ai4seo_plugin_activation_time" -> deprecated in V2.1.0
if (ai4seo_get_option("_ai4seo_plugin_activation_time") !== false) {
ai4seo_delete_option("_ai4seo_plugin_activation_time");
}
}
// V2.1.1:
if ($last_known_plugin_version && version_compare($last_known_plugin_version, '2.1.1', '<')) {
// delete old robhub environmental variable last_credit_balance_check
ai4seo_robhub_api()->delete_environmental_variable("last_credit_balance_check");
}
// === 2.2.X ================================================================================= \\
if ($last_known_plugin_version && version_compare($last_known_plugin_version, '2.2.0', '<')) {
// handle default visible meta tags setting change to new active meta tags setting
if (!isset($raw_settings[AI4SEO_SETTING_VISIBLE_META_TAGS]) || !$raw_settings[AI4SEO_SETTING_VISIBLE_META_TAGS]) {
// old default value for visible meta tags
ai4seo_update_setting(AI4SEO_SETTING_ACTIVE_META_TAGS, array("meta-title", "meta-description", "facebook-title", "facebook-description"));
}
// if visible meta tags were set, apply the same to active meta tags
if (isset($raw_settings[AI4SEO_SETTING_VISIBLE_META_TAGS]) && $raw_settings[AI4SEO_SETTING_VISIBLE_META_TAGS]) {
ai4seo_update_setting(AI4SEO_SETTING_ACTIVE_META_TAGS, $raw_settings[AI4SEO_SETTING_VISIBLE_META_TAGS]);
}
// set AI4SEO_SETTING_METADATA_FALLBACK_TWITTER_TITLE to 'facebook-title' and set AI4SEO_SETTING_METADATA_FALLBACK_TWITTER_DESCRIPTION to 'facebook-description'
ai4seo_update_setting(AI4SEO_SETTING_METADATA_FALLBACK_TWITTER_TITLE, 'facebook-title');
ai4seo_update_setting(AI4SEO_SETTING_METADATA_FALLBACK_TWITTER_DESCRIPTION, 'facebook-description');
}
// to finish the tidy up, we re-analyze the plugin performance and by adding notifications
ai4seo_analyze_plugin_performance();
// force push various notifications, if applicable
ai4seo_check_for_missing_entries_notification(true);
ai4seo_check_for_low_credits_balance_notification(true);
// refresh unread notifications count
ai4seo_refresh_unread_notifications_count();
}
// =========================================================================================== \\
/**
* Function to tidy up old ai4seo_cache table
* @return void
*/
function ai4seo_tidy_up_old_ai4seo_cache_table() {
global $wpdb;
$table_name = $wpdb->prefix . "ai4seo_cache";
// Check if the table exists
$table_exists = $wpdb->get_var($wpdb->prepare("SHOW TABLES LIKE %s", $table_name));
if ($table_exists) {
$sql = "SELECT * FROM $table_name";
$results = $wpdb->get_results($sql, ARRAY_A);
foreach ($results as $result) {
$post_id = sanitize_key($result["post_id"]);
$data = ai4seo_deep_sanitize(json_decode($result["data"], true));
ai4seo_save_generated_data_to_postmeta($post_id, $data);
}
// Drop the table
$wpdb->query("DROP TABLE IF EXISTS $table_name");
}
}
// =========================================================================================== \\
/**
* Function to init cron jobs
* @return void
*/
function ai4seo_init_cron_jobs() {
if (!ai4seo_init_robhub_api()) {
return;
}
if (ai4seo_does_user_need_to_accept_tos_toc_and_pp()) {
return;
}
// Add custom cron schedule
add_filter("cron_schedules", "ai4seo_add_cron_job_intervals");
// add cron jobs to automate content generation
add_action(AI4SEO_BULK_GENERATION_CRON_JOB_NAME, AI4SEO_BULK_GENERATION_CRON_JOB_NAME);
// add cron jobs to analyze current state of the plugins performance
add_action(AI4SEO_ANALYSE_PLUGIN_PERFORMANCE_CRON_JOB_NAME, AI4SEO_ANALYSE_PLUGIN_PERFORMANCE_CRON_JOB_NAME);
// schedule cron jobs if not already scheduled
ai4seo_schedule_cron_jobs();
}
// =========================================================================================== \\
/**
* Function to init robhub-api-communicator
* @return bool true if the class is found, false if not
*/
function ai4seo_init_robhub_api(): bool {
global $ai4seo_robhub_api;
// Include RobHubApiCommunicator class
include_once(ai4seo_get_includes_api_path("class-robhub-api-communicator.php"));
// return false if the class is not found
if (!class_exists("Ai4Seo_RobHubApiCommunicator")) {
return false;
}
// check if $ai4seo_robhub_api_communicator is already set
if ($ai4seo_robhub_api instanceof Ai4Seo_RobHubApiCommunicator) {
return true;
}
$product_activation_time = ai4seo_read_environmental_variable(AI4SEO_ENVIRONMENTAL_VARIABLE_PLUGIN_ACTIVATION_TIME);
$ai4seo_robhub_api = new Ai4Seo_RobHubApiCommunicator();
$ai4seo_robhub_api->set_environmental_variables_option_name(AI4SEO_ROBHUB_ENVIRONMENTAL_VARIABLES_OPTION_NAME);
$ai4seo_robhub_api->set_product_parameters("ai4seo", AI4SEO_PLUGIN_VERSION_NUMBER, $product_activation_time);
// do we need to accept the terms of service?
$does_user_need_to_accept_tos_toc_and_pp = ai4seo_does_user_need_to_accept_tos_toc_and_pp();
$ai4seo_robhub_api->set_does_user_need_to_accept_tos_toc_and_pp($does_user_need_to_accept_tos_toc_and_pp);
return true;
}
// =========================================================================================== \\
/**
* Adjusts the browser title for all AI for SEO plugin admin pages.
*
* Uses ai4seo_is_user_inside_our_plugin_admin_pages(), ai4seo_get_active_subpage(),
* ai4seo_get_active_post_type(), and ai4seo_get_plugins_menu_registry()
* to determine the current page label.
*
* @param string $admin_title Default admin title.
* @param string $title Original page title.
* @return string Filtered admin title.
*/
function ai4seo_filter_admin_title(string $admin_title, string $title ): string {
if ( ! ai4seo_is_user_inside_our_plugin_admin_pages() ) {
return $admin_title;
}
$registry = ai4seo_get_plugins_menu_registry();
$active_subpage = ai4seo_get_active_subpage();
$active_post_type_subpage = ai4seo_get_active_post_type_subpage();
// default label
$active_page_label = __( 'Dashboard', 'ai-for-seo' );
if ( ! empty( $active_subpage ) && isset( $registry[ $active_subpage ] ) ) {
// Static subpages: settings, media, account, help
$active_page_label = $registry[ $active_subpage ]['label'];
} elseif ( $active_subpage === 'post' && ! empty( $active_post_type_subpage ) && isset( $registry['post_types'][ $active_post_type_subpage ] ) ) {
// Dynamic post-type subpages
$active_page_label = $registry['post_types'][ $active_post_type_subpage ]['label'];
}
$website_name = get_bloginfo( 'name' );
// build everything together and sanitize
$browser_title = $active_page_label . ' ‹ ' . AI4SEO_PLUGIN_NAME . ' ‹ ' . $website_name;
$browser_title = wp_strip_all_tags( $browser_title );
$browser_title = str_replace( array( '&', '&' ), '&', $browser_title );
$browser_title = str_replace( array( '<', '<' ), '<', $browser_title );
$browser_title = str_replace( array( '>', '>' ), '>', $browser_title );
$browser_title = str_replace( array( '"', '"' ), '"', $browser_title );
$browser_title = str_replace( array( ''', ''' ), "'", $browser_title );
return $browser_title;
}
// === FUNCTION TO ADD MENU-ITEM TO MAIN MENU ================================================ \\
/**
* Build a registry of AI4SEO menu entries: labels and slugs.
*
* @return array{
* dashboard: array{label:string, slug:string},
* media: array{label:string, slug:string},
* account: array{label:string, slug:string},
* settings: array{label:string, slug:string},
* help: array{label:string, slug:string},
* post_types: array
* }
*/
function ai4seo_get_plugins_menu_registry(): array {
// Static pages.
$dashboard_slug = str_replace( '?page=', '', ai4seo_get_subpage_url( 'dashboard', array(), false ) ); // typically 'ai-for-seo'
$settings_slug = str_replace( '?page=', '', ai4seo_get_subpage_url( 'settings', array(), false ) ); // e.g. 'ai-for-seo&ai4seo_subpage=settings'
$media_slug = str_replace( '?page=', '', ai4seo_get_subpage_url( 'media', array(), false ) ); // e.g. 'ai-for-seo&ai4seo_subpage=media'
$account_slug = str_replace( '?page=', '', ai4seo_get_subpage_url( 'account', array(), false ) ); // e.g. 'ai-for-seo&ai4seo_subpage=account'
$help_slug = str_replace( '?page=', '', ai4seo_get_subpage_url( 'help', array(), false ) ); // e.g. 'ai-for-seo&ai4seo_subpage=help'
// Dynamic post-type pages: use a stable slug (no pagination or other volatile args).
$post_types = ai4seo_get_supported_post_types();
$post_type_map = array();
foreach ( $post_types as $this_post_type ) {
$this_post_type = sanitize_key( $this_post_type );
$label = ai4seo_get_nice_label( ai4seo_get_post_type_translation( $this_post_type, true ) );
$slug = AI4SEO_PLUGIN_IDENTIFIER . '&ai4seo_subpage=post&ai4seo_post_type=' . $this_post_type;
$post_type_map[ $this_post_type ] = array(
'label' => $label,
'slug' => $slug,
);
}
return array(
'dashboard' => array(
'label' => __( 'Dashboard', 'ai-for-seo' ),
'slug' => $dashboard_slug,
),
'media' => array(
'label' => _n( 'Media', 'Media', 2, 'ai-for-seo' ),
'slug' => $media_slug,
),
'account' => array(
'label' => __( 'Account', 'ai-for-seo' ),
'slug' => $account_slug,
),
'settings' => array(
'label' => __( 'Settings', 'ai-for-seo' ),
'slug' => $settings_slug,
),
'help' => array(
'label' => __( 'Help', 'ai-for-seo' ),
'slug' => $help_slug,
),
'post_types' => $post_type_map,
);
}
// =========================================================================================== \\
/**
* Register AI4SEO menu and submenus.
*
* @return void
*/
function ai4seo_add_menu_entries() {
$svg_tags = ai4seo_get_svg_tags();
if ( ! isset( $svg_tags['ai-for-seo-main-menu-icon'] ) ) {
return;
}
$encoded_svg = 'data:image/svg+xml;base64,' . base64_encode( $svg_tags['ai-for-seo-main-menu-icon'] );
// Top-level title with notification bubble.
$menu_title = AI4SEO_PLUGIN_NAME;
$notification_count = (int) ai4seo_get_num_unread_notification();
if ( $notification_count > 0 ) {
$menu_title .= " {$notification_count}";
}
// Central registry for labels and slugs.
$plugins_menu_registries = ai4seo_get_plugins_menu_registry();
// Top-level.
add_menu_page(
AI4SEO_PLUGIN_NAME,
$menu_title, // Contains markup for bubble. Keep as-is.
'edit_posts',
AI4SEO_PLUGIN_IDENTIFIER,
'ai4seo_include_menu_frame_file',
$encoded_svg,
99
);
// Dashboard (main page uses parent slug as submenu slug).
add_submenu_page(
AI4SEO_PLUGIN_IDENTIFIER,
$plugins_menu_registries['dashboard']['label'] . ' - ' . AI4SEO_PLUGIN_NAME,
$plugins_menu_registries['dashboard']['label'],
'edit_posts',
AI4SEO_PLUGIN_IDENTIFIER,
'ai4seo_include_menu_frame_file'
);
// Dynamic post-type submenus.
foreach ( $plugins_menu_registries['post_types'] as $this_post_type ) {
add_submenu_page(
AI4SEO_PLUGIN_IDENTIFIER,
$this_post_type['label'] . ' - ' . AI4SEO_PLUGIN_NAME,
$this_post_type['label'],
'edit_posts',
$this_post_type['slug'],
'ai4seo_include_menu_frame_file'
);
}
// Media.
add_submenu_page(
AI4SEO_PLUGIN_IDENTIFIER,
$plugins_menu_registries['media']['label'] . ' - ' . AI4SEO_PLUGIN_NAME,
$plugins_menu_registries['media']['label'],
'edit_posts',
$plugins_menu_registries['media']['slug'],
'ai4seo_include_menu_frame_file'
);
// Account.
add_submenu_page(
AI4SEO_PLUGIN_IDENTIFIER,
$plugins_menu_registries['account']['label'] . ' - ' . AI4SEO_PLUGIN_NAME,
$plugins_menu_registries['account']['label'],
'edit_posts',
$plugins_menu_registries['account']['slug'],
'ai4seo_include_menu_frame_file'
);
// Settings.
add_submenu_page(
AI4SEO_PLUGIN_IDENTIFIER,
$plugins_menu_registries['settings']['label'] . ' - ' . AI4SEO_PLUGIN_NAME,
$plugins_menu_registries['settings']['label'],
'edit_posts',
$plugins_menu_registries['settings']['slug'],
'ai4seo_include_menu_frame_file'
);
// Help.
add_submenu_page(
AI4SEO_PLUGIN_IDENTIFIER,
$plugins_menu_registries['help']['label'] . ' - ' . AI4SEO_PLUGIN_NAME,
$plugins_menu_registries['help']['label'],
'edit_posts',
$plugins_menu_registries['help']['slug'],
'ai4seo_include_menu_frame_file'
);
}
// =========================================================================================== \\
/**
* Mark our top-level menu as current when any AI for SEO page is open.
*
* @param string|null $parent_file
* @return string|null The slug of the current top-level menu (if any).
*/
function ai4seo_mark_parent_menu_active(?string $parent_file ): ?string {
if ( ai4seo_is_user_inside_our_plugin_admin_pages() ) {
$parent_file = AI4SEO_PLUGIN_IDENTIFIER;
}
return $parent_file;
}
// =========================================================================================== \\
/**
* Mark the correct submenu entry as current.
*
* @param string|null $submenu_file
* @return string|null The slug of the current submenu entry (if any).
*/
function ai4seo_mark_submenu_active(?string $submenu_file): ?string {
if ( ai4seo_is_user_inside_our_plugin_admin_pages() ) {
// Central registry for labels and slugs.
$plugins_menu_registries = ai4seo_get_plugins_menu_registry();
if ($active_post_type = ai4seo_get_active_post_type_subpage()) {
$submenu_file = $plugins_menu_registries['post_types'][$active_post_type]['slug'] ?? $submenu_file;
} elseif ( $active_subpage = ai4seo_get_active_subpage() ) {
$submenu_file = $plugins_menu_registries[$active_subpage]['slug'] ?? $submenu_file;
} else {
$submenu_file = AI4SEO_PLUGIN_IDENTIFIER;
}
}
return $submenu_file;
}
// === FUNCTION TO DISPLAY MENU FRAME ===================================================== \\
/**
* Function to display the menu frame
* @return void
*/
function ai4seo_include_menu_frame_file() {
include_once(ai4seo_get_plugin_dir_path("includes/menu-frame.php"));
}
// =========================================================================================== \\
/**
* Function to add modal schemas to the footer
* @return void
*/
function ai4seo_include_modal_schemas_file() {
include_once(ai4seo_get_includes_modal_schemas_path("autoload-modal-schemas.php"));
}
// =========================================================================================== \\
function ai4seo_enqueue_frontend_scripts() {
global $ai4seo_scripts_version_number;
// prevent multiple calls of this function
if (!ai4seo_singleton(__FUNCTION__)) {
return;
}
// check if we are outside the admin area
if (is_admin()) {
return;
}
// Enqueue ai-for-seo-alt-text-injection
$is_render_level_alt_text_enabled = ai4seo_get_setting(AI4SEO_SETTING_ENABLE_RENDER_LEVEL_ALT_TEXT_INJECTION);
$is_js_alt_text_enabled = ai4seo_get_setting(AI4SEO_SETTING_ENABLE_JS_ALT_TEXT_INJECTION);
if ($is_render_level_alt_text_enabled && $is_js_alt_text_enabled) {
wp_enqueue_script(AI4SEO_INJECTION_SCRIPTS_HANDLE, ai4seo_get_assets_js_path("ai-for-seo-alt-text-injection.js"), array("jquery"), $ai4seo_scripts_version_number, true);
}
}
// === FUNCTION TO ENQUEUE JAVASCRIPT- AND CSS-FILES ========================================= \\
/**
* Function to enqueue javascript- and css-files
* @return void
*/
function ai4seo_enqueue_admin_scripts() {
global $ai4seo_scripts_version_number;
// prevent multiple calls of this function
if (!ai4seo_singleton(__FUNCTION__)) {
return;
}
wp_enqueue_script("wp-i18n");
// Register and enqueue stylesheet
wp_register_style(AI4SEO_STYLES_HANDLE, ai4seo_get_assets_css_path("ai-for-seo-styles.css"), "", $ai4seo_scripts_version_number);
wp_enqueue_style(AI4SEO_STYLES_HANDLE);
// Enqueue javascript-file
wp_enqueue_script(AI4SEO_SCRIPTS_HANDLE, ai4seo_get_assets_js_path("ai-for-seo-scripts.js"), array("jquery", "wp-i18n"), $ai4seo_scripts_version_number, true);
// load translations
load_plugin_textdomain("ai-for-seo");
// Set localization parameters
ai4seo_set_localization_parameters();
/**
* Prevent optimizers from combining/caching the main script which contains a localized nonce.
*/
add_filter( 'script_loader_tag', function( $tag, $handle, $src ) {
if ( $handle === AI4SEO_SCRIPTS_HANDLE ) {
// LiteSpeed/Autoptimize respect data-no-optimize.
$tag = str_replace( '" . __("I - General Definitions", "ai-for-seo") . "";
$html .= "";
$html .= "
" . sprintf(__("This plugin was created and is maintained, including all updates and support, by %s, a German SEO agency (hereinafter referred to as '%s').", "ai-for-seo"), AI4SEO_PLUGIN_AUTHOR_COMPANY_NAME, AI4SEO_PLUGIN_AUTHOR_COMPANY_ABBREVIATION) . "
";
$html .= "
" . __("These Terms of Service outline your rights and responsibilities when using the AI for SEO plugin. Please read them carefully.", "ai-for-seo") . "
";
$html .= "
" . __("These Terms of Service are governed by the laws of Germany, and any disputes shall be resolved under German jurisdiction.", "ai-for-seo") . "
";
$html .= "";
$html .= "
" . __("II - General Acknowledgements", "ai-for-seo") . "
";
$html .= "";
$html .= "
" . sprintf(__("I have read and accept the Terms and Conditions and Privacy Policy of %s.", "ai-for-seo"), AI4SEO_TERMS_AND_CONDITIONS_URL, AI4SEO_PRIVACY_POLICY_URL, AI4SEO_PLUGIN_AUTHOR_COMPANY_ABBREVIATION) . "
";
$html .= "
" . sprintf(__("%s will not be liable for any direct, indirect, incidental, or consequential damages arising from the use of the plugin or generated content.", "ai-for-seo"), AI4SEO_PLUGIN_AUTHOR_COMPANY_ABBREVIATION) . "
";
$html .= "";
$html .= "
" . __("III - User Responsibilities", "ai-for-seo") . "
";
$html .= "";
$html .= "
" . __("I confirm that my content will be free from references to illegal drugs, violence, explicit material or otherwise illegal material.", "ai-for-seo") . "
";
$html .= "
" . __("I understand that AI may make errors, and I am responsible for reviewing all generated results to ensure accuracy and compliance with applicable laws.", "ai-for-seo") . "
";
$html .= "
" . sprintf(__("I acknowledge that I am solely responsible for how the generated data is used on my website, and %s is not liable for any misuse or improper application of the data.", "ai-for-seo"), AI4SEO_PLUGIN_AUTHOR_COMPANY_ABBREVIATION) . "
";
$html .= "
" . __("I will ensure that my use of the plugin complies with all applicable laws and regulations in my jurisdiction.", "ai-for-seo") . "
";
$html .= "
" . sprintf(__("I understand that using certain features within the plugin will consume Credits based on the specific feature. If higher-than-expected credit consumption occurs due to user actions, whether intentional or unintentional, Credits cannot be refunded or reversed unless %s determines the user was not responsible. However, the right to a 100%% refund within the 14-day money-back guarantee period still applies under these circumstances.", "ai-for-seo"), AI4SEO_PLUGIN_AUTHOR_COMPANY_ABBREVIATION) . "
";
$html .= "
" . __("I may request a full refund within 14 days of the initial purchase if not satisfied with the plugin’s performance, as outlined in our money-back guarantee policy. This refund policy applies only to monthly and yearly renewable subscriptions and does not cover Custom Credits Packs or Pay-as-you-go purchases.", "ai-for-seo") . "
";
$html .= "";
$html .= "
" . __("IV - Data Ownership, Handling and Lifetime", "ai-for-seo") . "
";
$html .= "";
$html .= "
" . sprintf(__("All data generated through the AI for SEO plugin remains the intellectual property of the user, provided it does not violate the terms of service. %s holds no claims to ownership of user-generated content.", "ai-for-seo"), AI4SEO_PLUGIN_AUTHOR_COMPANY_ABBREVIATION) . "
";
$html .= "
" . sprintf(__("%s complies with applicable data protection regulations, including the GDPR and DSGVO.", "ai-for-seo"), AI4SEO_PLUGIN_AUTHOR_COMPANY_ABBREVIATION) . "
";
$html .= "
" . sprintf(__("I agree that, in order to execute certain functions, data will be sent to %s's servers. This content will only be used and stored for purposes stated in the Terms and Conditions and Privacy Policy.", "ai-for-seo"), AI4SEO_PLUGIN_AUTHOR_COMPANY_ABBREVIATION, AI4SEO_TERMS_AND_CONDITIONS_URL, AI4SEO_PRIVACY_POLICY_URL) . "
";
$html .= "
" . sprintf(__("When accepting these Terms of Service, %s may collect and store certain information, including the user’s website URL, website name, email address, IP address, the version of the Terms accepted, and the timestamp of acceptance. This data is collected solely for compliance purposes and will be retained securely for the period necessary to fulfill legal obligations or until account deletion, as outlined in our Privacy Policy.", "ai-for-seo"), AI4SEO_PLUGIN_AUTHOR_COMPANY_ABBREVIATION, AI4SEO_PRIVACY_POLICY_URL) . "
";
$html .= "
" . sprintf(__("Data will be stored only for as long as necessary to fulfill the stated purpose and will be deleted in accordance with the data retention policy outlined in the Privacy Policy.", "ai-for-seo"), AI4SEO_PRIVACY_POLICY_URL) . "
";
$html .= "
" . sprintf(__("I may request the deletion of my data at any time, and %s will comply unless the data is required for fulfilling contractual or legal obligations. Requests can be sent to %s.", "ai-for-seo"), AI4SEO_PLUGIN_AUTHOR_COMPANY_ABBREVIATION, AI4SEO_SUPPORT_EMAIL, AI4SEO_SUPPORT_EMAIL) . "
";
$html .= "";
$html .= "
" . __("V - Third-parties and partners", "ai-for-seo") . "
";
$html .= "";
$html .= "
" . sprintf(__("I agree that, in order to execute certain functions, data from my website and its content may be sent to third-party services, including OpenAI.", "ai-for-seo"), AI4SEO_OPENAI_URL) . "
";
$html .= "
" . sprintf(__("I will adhere to OpenAI's Terms of Use at all times.", "ai-for-seo"), AI4SEO_OPENAI_TERMS_OF_USE_URL) . "
";
$html .= "
" . __("I specifically confirm that my content will be free from references to illegal drugs, extreme violence, or explicit material.", "ai-for-seo") . "
";
$html .= "";
$html .= "
" . __("VI - Rights and Modifications", "ai-for-seo") . "
";
$html .= "";
$html .= "
" . sprintf(__("%s reserves the right to terminate access to the plugin or revoke usage rights at any time if the terms are violated. In the event of termination, I will no longer have access to the plugin and any associated services.", "ai-for-seo"), AI4SEO_PLUGIN_AUTHOR_COMPANY_ABBREVIATION) . "
";
$html .= "
" . sprintf(__("%s reserves the right to modify these terms at any time. Users will be notified of any significant changes.", "ai-for-seo"), AI4SEO_PLUGIN_AUTHOR_COMPANY_ABBREVIATION) . "
";
$html .= "";
return $html;
}
// =========================================================================================== \\
/**
* Called via AJAX - On reject of the terms of service -> deactivate plugin
* @return void
*/
function ai4seo_reject_tos() {
// Make sure that this function is only called once
if (!ai4seo_singleton(__FUNCTION__)) {
return;
}
// check if we are in the admin area of WordPress
if (!is_admin()) {
return;
}
// perform the reject terms call
ai4seo_robhub_api()->perform_reject_terms_call(AI4SEO_TOS_VERSION_TIMESTAMP);
// uninstall the plugin
ai4seo_deactivate_plugin();
ai4seo_send_json_success();
}
// =========================================================================================== \\
/**
* Called via AJAX - On accept of the terms of service -> save the timestamp
* @return void
*/
function ai4seo_accept_tos() {
// Make sure that this function is only called once
if (!ai4seo_singleton(__FUNCTION__)) {
return;
}
// check if we are in the admin area of WordPress
if (!is_admin()) {
return;
}
// check if we accepted tos, toc and pp before
$tos_toc_and_pp_accepted_time = (int) ai4seo_read_environmental_variable(AI4SEO_ENVIRONMENTAL_VARIABLE_TOS_TOC_AND_PP_ACCEPTED_TIME);
// check if we accepted enhanced reporting before
$enhanced_reporting_accepted = (bool) ai4seo_read_environmental_variable(AI4SEO_ENVIRONMENTAL_VARIABLE_ENHANCED_REPORTING_ACCEPTED);
ai4seo_update_environmental_variable(AI4SEO_ENVIRONMENTAL_VARIABLE_TOS_TOC_AND_PP_ACCEPTED_TIME, time());
// handle enhanced reporting -> only save changes if we see the tos for the first time or the user has not accepted it before
// not handling the save here only because the user did not see the checkbox in the modal
if (!$tos_toc_and_pp_accepted_time || !$enhanced_reporting_accepted) {
// check for $_POST["accepted_enhanced_reporting"]
$enhanced_reporting_accepted = isset($_POST["accepted_enhanced_reporting"]) && $_POST["accepted_enhanced_reporting"] == "true";
if ($enhanced_reporting_accepted) {
ai4seo_update_environmental_variable(AI4SEO_ENVIRONMENTAL_VARIABLE_ENHANCED_REPORTING_ACCEPTED, true);
ai4seo_update_environmental_variable(AI4SEO_ENVIRONMENTAL_VARIABLE_ENHANCED_REPORTING_ACCEPTED_TIME, time());
}
}
// set tos accept details to database to share it with the maker of the plugin
ai4seo_set_tos_accept_details($enhanced_reporting_accepted, "accepted tos, toc and pp");
ai4seo_send_json_success();
}
// =========================================================================================== \\
/**
* Set the ToS Acceptance details to the database
* @param $accepted_enhanced_reporting bool Whether the user agreed to the extended data collection
* @param $action string The action that was performed
* @return void
*/
function ai4seo_set_tos_accept_details(bool $accepted_enhanced_reporting, string $action = "unknown") {
// collect additional data and put it into the wp_option "AI4SEO_ADDITIONAL_TOS_ACCEPT_DETAILS"
$additional_tos_accept_details = array(
"action" => sanitize_text_field($action),
"website_url" => sanitize_text_field(get_site_url()),
"website_name" => sanitize_text_field(get_bloginfo("name")),
"email_address" => sanitize_email(ai4seo_get_option("admin_email")),
"client_ip_address" => ai4seo_get_client_ip(),
"server_ip_address" => ai4seo_get_server_ip(),
"user_agent" => ai4seo_get_client_user_agent(),
"tos_version" => AI4SEO_TOS_VERSION_TIMESTAMP,
"timestamp" => time(),
"accepted_extended_data_collection" => $accepted_enhanced_reporting ? "1" : "0"
);
$additional_tos_accept_details = ai4seo_deep_sanitize($additional_tos_accept_details);
ai4seo_update_option(AI4SEO_ADDITIONAL_TOS_ACCEPT_DETAILS_OPTION_NAME, $additional_tos_accept_details);
}
// =========================================================================================== \\
/**
* Function to send the additional tos accept details, if available in the database
* @return void
*/
function ai4seo_send_additional_tos_accept_details() {
// Make sure that the user is allowed to use this plugin
if (!ai4seo_can_manage_this_plugin()) {
return;
}
// check in wp_options if we have additional tos accept details
$additional_tos_accept_details = ai4seo_get_option(AI4SEO_ADDITIONAL_TOS_ACCEPT_DETAILS_OPTION_NAME);
$additional_tos_accept_details = ai4seo_deep_sanitize($additional_tos_accept_details);
if (!$additional_tos_accept_details) {
return;
}
$new_tos_details_checksum = ai4seo_get_array_checksum($additional_tos_accept_details);
$last_tos_details_checksum = ai4seo_read_environmental_variable(AI4SEO_ENVIRONMENTAL_VARIABLE_LAST_TOS_DETAILS_CHECKSUM);
// prevent re-sending the same data
if ($new_tos_details_checksum === $last_tos_details_checksum) {
// delete the additional tos accept details from the database
ai4seo_delete_option(AI4SEO_ADDITIONAL_TOS_ACCEPT_DETAILS_OPTION_NAME);
return;
}
// prevent re-sending the same data using a timestamp of the last try
// only allow to send this data once every 1 hour
$tried_to_send_this_data_before_timestamp = (int) ai4seo_get_option(AI4SEO_ADDITIONAL_TOS_ACCEPT_DETAILS_LAST_TRY_TIMESTAMP_OPTION_NAME);
if ($tried_to_send_this_data_before_timestamp && $tried_to_send_this_data_before_timestamp > (time() - 3600)) {
return;
}
ai4seo_update_option(AI4SEO_ADDITIONAL_TOS_ACCEPT_DETAILS_LAST_TRY_TIMESTAMP_OPTION_NAME, time());
// call robhub api endpoint "accept-terms" with the additional tos accept details
$response = ai4seo_robhub_api()->call("client/accept-terms", $additional_tos_accept_details);
//check response
if (!ai4seo_robhub_api()->was_call_successful($response)) {
error_log("AI4SEO: Invalid response from RobHub API. #1712121224");
return;
}
// on success...
// remove the additional tos accept details from the database
ai4seo_delete_option(AI4SEO_ADDITIONAL_TOS_ACCEPT_DETAILS_OPTION_NAME);
ai4seo_delete_option(AI4SEO_ADDITIONAL_TOS_ACCEPT_DETAILS_LAST_TRY_TIMESTAMP_OPTION_NAME);
// save the checksum of the new tos details
ai4seo_update_environmental_variable(AI4SEO_ENVIRONMENTAL_VARIABLE_LAST_TOS_DETAILS_CHECKSUM, $new_tos_details_checksum);
}
// ___________________________________________________________________________________________ \\
// === LATEST ACTIVITY ======================================================================= \\
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ \\
/**
* Function to add an entry to the latest activity log
* @param int $post_id The post id this entry refers to
* @param string $status The status of the action (success, error)
* @param string $action The action that was performed ("metadata-manually-generated", "metadata-bulk-generated", "attachment-attributes-manually-generated", "attachment-attributes-bulk-generated")
* @param int $cost The cost of the action in credits
* @param string $details The details of the action
* @return bool
*/
function ai4seo_add_latest_activity_entry(int $post_id, string $status, string $action, int $cost = 0, string $details = ""): bool {
$new_entry["timestamp"] = time();
// check if the post_id is a valid post id
if ($post_id < 0) {
error_log("AI4SEO: Invalid post id in latest activity log. #231410125");
return false;
}
// check if the status is one of the allowed statuses (success, error)
$status = sanitize_text_field($status);
if (!in_array($status, array("success", "error"))) {
return false;
}
$action = sanitize_text_field($action);
if (!in_array($action, array("metadata-manually-generated", "metadata-bulk-generated", "attachment-attributes-manually-generated", "attachment-attributes-bulk-generated"))) {
error_log("AI4SEO: Invalid action in latest activity log. #241410125");
return false;
}
// check if the cost is valid
if ($cost < 0) {
error_log("AI4SEO: Invalid cost in latest activity log. #251410125");
return false;
}
// read additional post data
$post_type = get_post_type($post_id);
// check post type (alphanumeric, - and _ allowed)
$post_type = sanitize_text_field($post_type);
if (!preg_match("/^[a-zA-Z0-9_-]+$/", $post_type)) {
return false;
}
// check title
$title = sanitize_text_field(get_the_title($post_id));
$title = ai4seo_mb_substr($title, 0 , 50);
$title = sanitize_text_field($title);
if ($post_type == "attachment") {
$url = get_edit_post_link($post_id);
} else {
$url = get_permalink($post_id);
}
if (!$url) {
$url = "";
}
// check url
$url = sanitize_url($url);
if ($url) {
$url = esc_url($url);
}
// check details
$details = sanitize_text_field($details);
// build the new entry
$new_entry = array(
"timestamp" => time(),
"post_id" => $post_id,
"post_type" => $post_type,
"status" => $status,
"action" => $action,
"cost" => $cost,
"title" => $title,
"url" => $url,
"details" => $details
);
// read the latest activity logs
$latest_activity = ai4seo_get_option(AI4SEO_LATEST_ACTIVITY_OPTION_NAME, array());
// add the new entry
array_unshift($latest_activity, $new_entry);
// remove the oldest entry if necessary
if (count($latest_activity) >= AI4SEO_MAX_LATEST_ACTIVITY_LOGS) {
array_pop($latest_activity);
}
// save the new latest activity logs
ai4seo_update_option(AI4SEO_LATEST_ACTIVITY_OPTION_NAME, $latest_activity);
return true;
}
// ___________________________________________________________________________________________ \\
// === PAY AS YOU GO ========================================================================= \\
// ¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯¯ \\
function ai4seo_send_pay_as_you_go_settings() {
// call robhub api endpoint "payg-settings" with current payg settings
$robhub_endpoint = "client/payg-settings";
$payg_settings = array();
$payg_settings[AI4SEO_SETTING_PAYG_ENABLED] = (bool) ai4seo_get_setting(AI4SEO_SETTING_PAYG_ENABLED);
$payg_settings[AI4SEO_SETTING_PAYG_STRIPE_PRICE_ID] = ai4seo_get_setting(AI4SEO_SETTING_PAYG_STRIPE_PRICE_ID);
$payg_settings[AI4SEO_SETTING_PAYG_DAILY_BUDGET] = (int) ai4seo_get_setting(AI4SEO_SETTING_PAYG_DAILY_BUDGET);
$payg_settings[AI4SEO_SETTING_PAYG_MONTHLY_BUDGET] = (int) ai4seo_get_setting(AI4SEO_SETTING_PAYG_MONTHLY_BUDGET);
$payg_settings = ai4seo_deep_sanitize($payg_settings);
$response = ai4seo_robhub_api()->call($robhub_endpoint, $payg_settings);
// check response
if (!ai4seo_robhub_api()->was_call_successful($response)) {
error_log("AI4SEO: Invalid response from RobHub API. #361217325");
return false;
}
// remove potential previous error notification
ai4seo_remove_notification("payg-status-error");
return true;
}