siteseo
Last commit date
assets
2 months ago
main
2 months ago
functions.php
6 months ago
readme.txt
2 months ago
siteseo.php
2 months ago
functions.php
245 lines
| 1 | <?php |
| 2 | /* |
| 3 | * SITESEO |
| 4 | * https://siteseo.io |
| 5 | * (c) SiteSEO Team |
| 6 | */ |
| 7 | |
| 8 | if(!defined('ABSPATH')){ |
| 9 | die('HACKING ATTEMPT!'); |
| 10 | } |
| 11 | |
| 12 | function siteseo_admin_header(){ |
| 13 | \SiteSEO\Settings\Util::admin_header(); |
| 14 | } |
| 15 | |
| 16 | function siteseo_submit_button($value = ''){ |
| 17 | \SiteSEO\Settings\Util::submit_btn(); |
| 18 | } |
| 19 | |
| 20 | function siteseo_suggestions_variable(){ |
| 21 | return [ |
| 22 | '%%sep%%' => 'Separator', |
| 23 | '%%sitetitle%%' => 'Site Title', |
| 24 | '%%tagline%%' => 'Tagline', |
| 25 | '%%post_title%%' => 'Post title', |
| 26 | '%%post_excerpt%%' => 'Post excerpt', |
| 27 | '%%post_content%%' => 'Post content / product description', |
| 28 | '%%post_thumbnail_url%%' => 'Post thumbnail URL', |
| 29 | '%%post_url%%' => 'Post url', |
| 30 | '%%post_date%%' => 'Post date', |
| 31 | '%%post_modified_date%%' => 'Post modified date', |
| 32 | '%%post_author%%' => 'Post author', |
| 33 | '%%post_category%%' => 'Post category', |
| 34 | '%%post_tag%%' => 'Post_tag', |
| 35 | '%%_category_title%%' => 'Category title', |
| 36 | '%%_category_description%%' => 'Category description', |
| 37 | '%%tag_title%%' => 'Tag title', |
| 38 | '%%tag_description%%' => 'Tag description', |
| 39 | '%%term_title%%' => 'Term title', |
| 40 | '%%term_description%%' => 'Term description', |
| 41 | '%%search_keywords%%' => 'Search keywords', |
| 42 | '%%current_pagination%%' => 'Current number page', |
| 43 | '%%page%%' => 'Page number with context', |
| 44 | '%%cpt_plural%%' => 'Plural Post Type Archive name', |
| 45 | '%%archive_title%%' => 'Archive_title', |
| 46 | '%%archive_date%%' => 'Archive_date', |
| 47 | '%%archive_date_day%%' => 'Day Archive date', |
| 48 | '%%archive_date_month%%' => 'Month Archive title', |
| 49 | '%%archive_date_month_name%%' => 'Month name Archive title', |
| 50 | '%%archive_date_year%%' => 'Year Archive title', |
| 51 | '%%_cf_your_custom_field_name%%' => 'Custom fields from post, page, post type and term taxonomy', |
| 52 | '%%_ct_your_custom_taxonomy_slug%%' => 'Custom term taxonomy from post, page or post type', |
| 53 | '%%wc_single_cat%%' => 'Single product category', |
| 54 | '%%wc_single_tag%%' => 'Single product tag', |
| 55 | '%%wc_single_short_desc%%' => 'Single product short description', |
| 56 | '%%wc_single_price%%' => 'Single product price', |
| 57 | '%%wc_single_price_exe_tax' => 'Single product price taxes excluded', |
| 58 | '%%wc_sku%%' => 'Single SKU Product', |
| 59 | '%%currentday%%' => 'Current day', |
| 60 | '%%currentmonth%%' => 'Current month', |
| 61 | '%%currentmonth_short%%' => 'Current month in 3 letter', |
| 62 | '%%currentyear%%' => 'Current year', |
| 63 | '%%currentdate%%' => 'Current date', |
| 64 | '%%currenttime%%' => 'Current time', |
| 65 | '%%author_first_name%%' => 'Author first name', |
| 66 | '%%author_last_name%%' => 'Author last name', |
| 67 | '%%author_website%%' => 'Author website', |
| 68 | '%%author_nickname%%' => 'Author nickname', |
| 69 | '%%author_bio%%' => 'Author biography', |
| 70 | '%%_ucf_your_user_meta%%' => 'Custom User Meta', |
| 71 | '%%currentmonth_num%%' => 'Current month in digital format', |
| 72 | '%%target_keyword%%' => 'Target keywords', |
| 73 | '%%wc_parent_cat%%' => 'Product Single Parent Category', |
| 74 | ]; |
| 75 | } |
| 76 | |
| 77 | function siteseo_suggestion_button(){ |
| 78 | |
| 79 | $suggest_variable = siteseo_suggestions_variable(); |
| 80 | |
| 81 | if(empty($suggest_variable)){ |
| 82 | return; |
| 83 | } |
| 84 | |
| 85 | echo '<button class="tag-select-btn"><span id="icon" class="dashicons dashicons-arrow-down-alt2"></span></button> |
| 86 | <div class="siteseo-suggestions-wrapper" style="position:relative;"> |
| 87 | <div class="siteseo-suggetion"> |
| 88 | <div class="siteseo-search-box-container"> |
| 89 | <input type="text" class="siteseo-search-box" placeholder="Search a tag..."> |
| 90 | </div> |
| 91 | <div class="siteseo-suggestions-container">'; |
| 92 | foreach($suggest_variable as $key =>$value){ |
| 93 | echo '<div class="section">'.esc_html($value).' |
| 94 | <div class="item"> |
| 95 | <div class="tag">'.esc_html($key).'</div> |
| 96 | </div> |
| 97 | </div>'; |
| 98 | } |
| 99 | echo '</div> |
| 100 | </div> |
| 101 | </div>'; |
| 102 | } |
| 103 | |
| 104 | function siteseo_suggestion_button_metabox(){ |
| 105 | $suggest_variable = siteseo_suggestions_variable(); |
| 106 | |
| 107 | if(empty($suggest_variable)){ |
| 108 | return; |
| 109 | } |
| 110 | |
| 111 | return '<button class="siteseo-tag-select-btn" type="button"> |
| 112 | <span id="icon" class="dashicons dashicons-arrow-down-alt2"></span> |
| 113 | </button> |
| 114 | <div class="siteseo-suggestions-wrapper" style="position:relative;"> |
| 115 | <div class="siteseo-suggetion"> |
| 116 | <div class="siteseo-search-box-container"> |
| 117 | <input type="text" class="search-box" placeholder="Search a tag..."> |
| 118 | </div> |
| 119 | <div class="siteseo-suggestions-container">' . |
| 120 | implode('', array_map(function($key, $value){ |
| 121 | return '<div class="section">'.esc_html($value).' |
| 122 | <div class="item"> |
| 123 | <div class="tag">'.esc_html($key).'</div> |
| 124 | </div> |
| 125 | </div>'; |
| 126 | }, array_keys($suggest_variable), $suggest_variable)). |
| 127 | '</div> |
| 128 | </div> |
| 129 | </div>'; |
| 130 | } |
| 131 | |
| 132 | function siteseo_get_docs_links(){ |
| 133 | $siteseo_docs = []; |
| 134 | |
| 135 | $siteseo_docs = [ |
| 136 | 'page_speed' => [ |
| 137 | 'api' => SITESEO_DOCS . 'api-cli-dev/add-your-google-page-speed-insights-api-key-to-siteseo/', |
| 138 | 'google' => 'https://console.cloud.google.com/apis/library/pagespeedonline.googleapis.com', |
| 139 | ] |
| 140 | ]; |
| 141 | |
| 142 | return $siteseo_docs; |
| 143 | } |
| 144 | |
| 145 | function siteseo_universal_assets(){ |
| 146 | global $siteseo, $post; |
| 147 | |
| 148 | $post_id = isset($post->ID) ? $post->ID : get_the_ID(); |
| 149 | |
| 150 | if(!current_user_can('edit_post', $post_id)){ |
| 151 | return; |
| 152 | } |
| 153 | |
| 154 | // Checking if it is a block editor |
| 155 | if(function_exists('get_current_screen')){ |
| 156 | $screen = get_current_screen(); |
| 157 | |
| 158 | if(!empty($screen) && method_exists($screen, 'is_block_editor') && $screen->is_block_editor() === true){ |
| 159 | if(empty($siteseo->advanced_settings['appearance_universal_metabox'])){ |
| 160 | return; |
| 161 | } |
| 162 | |
| 163 | $is_gutenberg = true; |
| 164 | } |
| 165 | } |
| 166 | |
| 167 | if ( |
| 168 | !empty($is_gutenberg) || |
| 169 | isset($_GET['fl_builder']) || |
| 170 | isset($_GET['elementor-preview']) || |
| 171 | isset($_GET['ct_builder']) || |
| 172 | isset($_GET['vc_editable']) || |
| 173 | isset($_GET['brizy_edit']) || |
| 174 | isset($_GET['tve']) || |
| 175 | isset($_GET['pagelayer-live']) || |
| 176 | (!empty(get_queried_object_id()) && is_admin_bar_showing()) // To show when user is viewing the page as a admin |
| 177 | && !is_category() && !is_tax() && !is_tag() // exclude |
| 178 | ) { |
| 179 | wp_enqueue_script('siteseo-universal-metabox', SITESEO_ASSETS_URL . '/js/universal-metabox.js', ['jquery'], SITESEO_VERSION); |
| 180 | wp_localize_script('siteseo-universal-metabox', 'siteseo_universal', [ |
| 181 | 'asset_url' => SITESEO_ASSETS_URL, |
| 182 | 'post_id' => $post_id, |
| 183 | 'site_url' => site_url(), |
| 184 | 'metabox_url' => admin_url('admin.php?page=siteseo-metabox-wizard'), |
| 185 | ]); |
| 186 | |
| 187 | if(!defined('SITEPAD') && defined('SITESEO_PRO_VERSION') && class_exists('\SiteSEOPro\AI')){ |
| 188 | add_action('wp_footer', '\SiteSEOPro\AI::modal'); |
| 189 | } |
| 190 | } |
| 191 | } |
| 192 | |
| 193 | function siteseo_post_types(){ |
| 194 | |
| 195 | $args = ['show_ui' => true, 'public' => true]; |
| 196 | |
| 197 | $post_types = get_post_types($args, 'objects', 'and'); |
| 198 | unset( |
| 199 | $post_types['attachment'], |
| 200 | $post_types['elementor_library'], |
| 201 | $post_types['customer_discount'], |
| 202 | $post_types['cuar_private_file'], |
| 203 | $post_types['cuar_private_page'], |
| 204 | $post_types['ct_template'], |
| 205 | $post_types['e-floating-buttons'], |
| 206 | $post_types['pagelayer-template'], |
| 207 | $post_types['hostim_footer'], |
| 208 | $post_types['mega_menu'] |
| 209 | ); |
| 210 | |
| 211 | return apply_filters('siteseo_post_types', $post_types); |
| 212 | |
| 213 | } |
| 214 | |
| 215 | function siteseo_user_can($cap){ |
| 216 | return current_user_can('manage_options') || current_user_can('siteseo_'. $cap); |
| 217 | } |
| 218 | |
| 219 | function siteseo_user_can_metabox(){ |
| 220 | if(!is_user_logged_in()){ |
| 221 | return false; |
| 222 | } |
| 223 | |
| 224 | global $siteseo; |
| 225 | |
| 226 | $metabox_roles = !empty($siteseo->advanced_settings['security_metaboxe_role']) ? $siteseo->advanced_settings['security_metaboxe_role'] : []; |
| 227 | |
| 228 | $user = wp_get_current_user(); |
| 229 | $user_role = current($user->roles); |
| 230 | |
| 231 | if(array_key_exists($user_role, $metabox_roles)){ |
| 232 | return false; |
| 233 | } |
| 234 | |
| 235 | return true; |
| 236 | } |
| 237 | |
| 238 | function siteseo_remove_elementor_description_meta_tag(){ |
| 239 | remove_action('wp_head', 'hello_elementor_add_description_meta_tag'); |
| 240 | } |
| 241 | |
| 242 | function siteseo_plugin_update_notice_filter($plugins = []){ |
| 243 | $plugins['siteseo/siteseo.php'] = 'SiteSEO'; |
| 244 | return $plugins; |
| 245 | } |