siteseo
Last commit date
assets
5 months ago
main
5 months ago
functions.php
6 months ago
readme.txt
5 months ago
siteseo.php
5 months ago
siteseo.php
242 lines
| 1 | <?php |
| 2 | /* |
| 3 | Plugin Name: SiteSEO - SEO Simplified |
| 4 | Plugin URI: https://siteseo.io/ |
| 5 | Description: SiteSEO is an easy, fast and powerful SEO plugin for WordPress. Unlock your Website's potential and Maximize your online visibility with our SiteSEO! |
| 6 | Author: Softaculous |
| 7 | Version: 1.3.5 |
| 8 | Requires at least: 5.0 |
| 9 | Author URI: https://siteseo.io/ |
| 10 | License: GPLv2 |
| 11 | Text Domain: siteseo |
| 12 | */ |
| 13 | |
| 14 | if(!defined('ABSPATH')){ |
| 15 | die('HACKING ATTEMPT!'); |
| 16 | } |
| 17 | |
| 18 | if(!function_exists('add_action')){ |
| 19 | echo 'You are not allowed to access this page directly.'; |
| 20 | exit; |
| 21 | } |
| 22 | |
| 23 | if(defined('SITESEO_VERSION')){ |
| 24 | return; |
| 25 | } |
| 26 | |
| 27 | define('SITESEO_VERSION', '1.3.5'); |
| 28 | define('SITESEO_FILE', __FILE__); |
| 29 | define('SITESEO_DOCS', 'https://siteseo.io/docs/'); |
| 30 | define('SITESEO_DIR_PATH', plugin_dir_path(SITESEO_FILE)); |
| 31 | define('SITESEO_DIR_URL', plugin_dir_url(SITESEO_FILE)); |
| 32 | define('SITESEO_ASSETS_PATH', SITESEO_DIR_PATH . 'assets'); |
| 33 | define('SITESEO_ASSETS_URL', SITESEO_DIR_URL . 'assets'); |
| 34 | define('SITESEO_DEV', file_exists(SITESEO_DIR_PATH.'DEV.php')); |
| 35 | |
| 36 | include_once(SITESEO_DIR_PATH . 'functions.php'); |
| 37 | |
| 38 | function siteseo_autoloader($class){ |
| 39 | if(!preg_match('/^SiteSEO\\\(.*)/is', $class, $m)){ |
| 40 | return; |
| 41 | } |
| 42 | |
| 43 | $m[1] = str_replace('\\', '/', $m[1]); |
| 44 | |
| 45 | // Include file |
| 46 | if(file_exists(SITESEO_DIR_PATH . 'main/'.strtolower($m[1]).'.php')){ |
| 47 | include_once(SITESEO_DIR_PATH.'main/'.strtolower($m[1]).'.php'); |
| 48 | } |
| 49 | } |
| 50 | |
| 51 | spl_autoload_register('siteseo_autoloader'); |
| 52 | |
| 53 | register_activation_hook(SITESEO_FILE, '\SiteSEO\Install::activate'); |
| 54 | register_deactivation_hook(SITESEO_FILE, '\SiteSEO\Install::deactivate'); |
| 55 | register_uninstall_hook(SITESEO_FILE, '\SiteSEO\Install::uninstall'); |
| 56 | add_action('plugins_loaded', 'siteseo_load_plugin'); |
| 57 | |
| 58 | function siteseo_load_plugin(){ |
| 59 | global $siteseo; |
| 60 | |
| 61 | if(empty($siteseo)){ |
| 62 | $siteseo = new StdClass(); |
| 63 | } |
| 64 | |
| 65 | // Loading all the options. |
| 66 | $siteseo->setting_enabled = get_option('siteseo_toggle', []); |
| 67 | $siteseo->titles_settings = get_option('siteseo_titles_option_name', []); |
| 68 | $siteseo->social_settings = get_option('siteseo_social_option_name', []); |
| 69 | $siteseo->advanced_settings = get_option('siteseo_advanced_option_name', []); |
| 70 | $siteseo->instant_settings = get_option('siteseo_instant_indexing_option_name', []); |
| 71 | $siteseo->sitemap_settings = get_option('siteseo_xml_sitemap_option_name', []); |
| 72 | $siteseo->analaytics_settings = get_option('siteseo_google_analytics_option_name', []); |
| 73 | |
| 74 | siteseo_check_update(); |
| 75 | |
| 76 | if(!empty($siteseo->setting_enabled['toggle-advanced'])){ |
| 77 | add_action('init','\SiteSEO\ImageSeo::init', 11); // Upload happens with AJAX so we need this here |
| 78 | } |
| 79 | |
| 80 | if(wp_doing_ajax()){ |
| 81 | \SiteSEO\Ajax::hooks(); |
| 82 | return; |
| 83 | } |
| 84 | |
| 85 | if(defined('SITESEO_PRO_VERSION') && version_compare(SITESEO_PRO_VERSION, '1.1.5', '<')){ |
| 86 | if(!function_exists('is_plugin_active')){ |
| 87 | require_once ABSPATH . 'wp-admin/includes/plugin.php'; |
| 88 | } |
| 89 | } |
| 90 | |
| 91 | // Image & Sitemap block |
| 92 | add_action('init', '\SiteSEO\Admin::register_sitmap_block'); |
| 93 | |
| 94 | // TOC |
| 95 | add_shortcode('siteseo_toc', '\SiteSEO\TableofContent::render_toc'); |
| 96 | add_action('init', '\SiteSEO\TableofContent::enable_toc'); |
| 97 | |
| 98 | if(!empty($siteseo->setting_enabled['toggle-xml-sitemap']) && !empty($siteseo->sitemap_settings['xml_sitemap_general_enable'])){ |
| 99 | add_filter('wp_sitemaps_enabled', '__return_false'); // Disabling default WP Sitemap |
| 100 | |
| 101 | add_action('init', '\SiteSEO\GenerateSitemap::add_rewrite_rules', 20); |
| 102 | add_action('template_redirect', '\SiteSEO\GenerateSitemap::handle_sitemap_requests', 0); |
| 103 | } |
| 104 | |
| 105 | if(!empty($siteseo->sitemap_settings['toggle-xml-sitemap']) && !empty($siteseo->sitemap_settings['xml_sitemap_general_enable'])){ |
| 106 | add_shortcode('siteseo_html_sitemap', '\SiteSEO\GenerateSitemap::html_sitemap'); |
| 107 | } |
| 108 | |
| 109 | // Redirect |
| 110 | add_action('template_redirect', '\SiteSEO\GoogleAnalytics::handle_custom_redirect'); |
| 111 | add_action('init', '\SiteSEO\Advanced::remove_wc_category_base'); |
| 112 | |
| 113 | if(!empty($siteseo->setting_enabled['toggle-instant-indexing']) && !empty($siteseo->instant_settings['instant_indexing_bing_api_key'])){ |
| 114 | add_action('template_redirect', '\SiteSEO\InstantIndexing::bing_txt_file', 0); |
| 115 | |
| 116 | if(!empty($siteseo->instant_settings['instant_indexing_automate_submission'])){ |
| 117 | add_action('transition_post_status', '\SiteSEO\InstantIndexing::on_status_change', 10, 3); |
| 118 | } |
| 119 | } |
| 120 | |
| 121 | \SiteSEO\Admin::permission(); |
| 122 | |
| 123 | if(!empty($siteseo->setting_enabled['toggle-advanced']) && empty($siteseo->advanced_settings['appearance_universal_metabox_disable']) && siteseo_user_can_metabox()){ |
| 124 | add_action('wp_enqueue_scripts', 'siteseo_universal_assets'); |
| 125 | add_action('enqueue_block_editor_assets', 'siteseo_universal_assets'); |
| 126 | |
| 127 | if(defined('SITESEO_PRO_VERSION') && version_compare(SITESEO_PRO_VERSION, '1.2.6', '>=')){ |
| 128 | add_action('wp_enqueue_scripts', '\SiteSEOPro\Admin::enqueue_metabox'); |
| 129 | add_action('enqueue_block_editor_assets', '\SiteSEOPro\Admin::enqueue_metabox'); |
| 130 | } |
| 131 | } |
| 132 | |
| 133 | if(!is_admin()){ |
| 134 | // Code that will be used in the frontend will go here. |
| 135 | |
| 136 | if(defined('WPB_VC_VERSION') && !empty($_GET['vc_editable']) && $_GET['vc_editable'] === 'true'){ |
| 137 | return; // WPBakery |
| 138 | } |
| 139 | |
| 140 | remove_action('wp_head', 'rel_canonical'); |
| 141 | add_action('after_setup_theme', 'siteseo_remove_elementor_description_meta_tag'); |
| 142 | |
| 143 | // Cookies enqueue |
| 144 | add_action('wp_enqueue_scripts', '\SiteSEO\Admin::cookies_bar'); |
| 145 | |
| 146 | // Titles and Metas |
| 147 | add_action('wp_head', '\SiteSEO\TitlesMetas::add_nositelinkssearchbox', 1); |
| 148 | add_action('wp_head', '\SiteSEO\TitlesMetas::add_canonical_url', 1); |
| 149 | add_filter('wp_title', '\SiteSEO\TitlesMetas::modify_site_title', 15, 2); |
| 150 | add_filter('pre_get_document_title', '\SiteSEO\TitlesMetas::modify_site_title', 15); |
| 151 | add_action('wp_head', '\SiteSEO\TitlesMetas::add_meta_description', 1); |
| 152 | add_filter('wp_robots', '\SiteSEO\TitlesMetas::advanced_metas', 999); |
| 153 | add_action('wp_head', '\SiteSEO\TitlesMetas::add_rel_link_pages', 9); |
| 154 | add_action('wp_head', '\SiteSEO\TitlesMetas::date_time_publish', 3); |
| 155 | |
| 156 | // Social |
| 157 | add_action('wp_head', '\SiteSEO\SocialMetas::add_social_graph', 1); |
| 158 | add_action('wp_head', '\SiteSEO\SocialMetas::fb_graph', 1); |
| 159 | add_action('wp_head', '\SiteSEO\SocialMetas::twitter_card', 1); |
| 160 | |
| 161 | // Sitemaps |
| 162 | add_action('init', '\SiteSEO\GenerateSitemap::settings', 5); |
| 163 | |
| 164 | // Image & Advanced |
| 165 | add_action('wp_head', '\SiteSEO\Advanced::tags'); |
| 166 | add_action('init', '\SiteSEO\Advanced::remove_links'); |
| 167 | |
| 168 | // Analaytics |
| 169 | add_action('init', '\SiteSEO\GoogleAnalytics::ga_render'); |
| 170 | |
| 171 | add_filter('post_link_category', '\SiteSEO\PrimaryCategory::add_primary_category', 10, 3); |
| 172 | add_filter('wc_product_post_type_link_product_cat', '\SiteSEO\PrimaryCategory::wc_primary_category', 10, 3); |
| 173 | add_filter('woocommerce_get_breadcrumb', '\SiteSEO\PrimaryCategory::replace_breadcrumb_categories', 10, 2); |
| 174 | |
| 175 | return; |
| 176 | } |
| 177 | |
| 178 | if(is_admin()){ |
| 179 | \SiteSEO\Admin::init(); |
| 180 | } |
| 181 | } |
| 182 | |
| 183 | function siteseo_check_update(){ |
| 184 | global $siteseo; |
| 185 | |
| 186 | $current_version = get_option('siteseo_version'); |
| 187 | $version = (int) str_replace('.', '', $current_version); |
| 188 | |
| 189 | // No update required |
| 190 | if($current_version == SITESEO_VERSION){ |
| 191 | return true; |
| 192 | } |
| 193 | |
| 194 | if($version < 115){ |
| 195 | // Older version had enable index, and if it was set it actually meant it was enabled. |
| 196 | $options = $siteseo->titles_settings['titles_single_titles']; |
| 197 | |
| 198 | if(!empty($options)){ |
| 199 | foreach($options as &$option){ |
| 200 | if(!empty($option['enable'])){ |
| 201 | unset($option['enable']); |
| 202 | $option['disabled'] = true; |
| 203 | } |
| 204 | } |
| 205 | |
| 206 | $siteseo->titles_settings['titles_single_titles'] = $options; |
| 207 | } |
| 208 | |
| 209 | update_option('siteseo_titles_option_name', $siteseo->titles_settings); |
| 210 | } |
| 211 | |
| 212 | if($version > 115 && $version < 117){ |
| 213 | $options = $siteseo->titles_settings['titles_single_titles']; |
| 214 | |
| 215 | // In 115 if enabled was true then the options will be enabled, which was an issue |
| 216 | // As it means user will have to manually enable every metabox option. |
| 217 | if(!empty($options)){ |
| 218 | foreach($options as &$option){ |
| 219 | if(!empty($option['enable'])){ |
| 220 | unset($option['enable']); |
| 221 | } elseif(isset($option['enable'])){ |
| 222 | $option['disabled'] = true; |
| 223 | unset($option['enable']); |
| 224 | } |
| 225 | } |
| 226 | |
| 227 | $siteseo->titles_settings['titles_single_titles'] = $options; |
| 228 | } |
| 229 | |
| 230 | update_option('siteseo_titles_option_name', $siteseo->titles_settings); |
| 231 | } |
| 232 | |
| 233 | // Is it first run ? |
| 234 | if(empty($current_version)){ |
| 235 | \SiteSEO\Install::activate(); |
| 236 | return; |
| 237 | } |
| 238 | |
| 239 | update_option('siteseo_version', SITESEO_VERSION); |
| 240 | } |
| 241 | |
| 242 |