/* Plugin Name: AI Snippet SEO Pro Plugin URI: https://rankpilotai.com Description: Centralized snippet generation via RankPilot AI. Uses a site token. Generates SEO-optimized snippets for posts, pages, and taxonomies with usage-limited tokens. Version: 1.0.0 Author: RankPilotAI Text Domain: ai-snippet-seo-pro Domain Path: /languages Requires at least: 5.8 Tested up to: 6.7.3 Requires PHP: 7.4 License: GPLv2 or later License URI: https://www.gnu.org/licenses/gpl-2.0.html */ if ( ! defined('ABSPATH') ) exit; define('AISSP_FILE', __FILE__); function aissp_plugin_activate() { $option_key = 'aissp_settings'; $opts = get_option($option_key,[]); if(!is_array($opts)) $opts=[]; if(empty($opts['site_token'])){ $opts['site_token'] = 'rp_'.wp_generate_password(20,false,false); update_option($option_key,$opts); } } register_activation_hook(__FILE__,'aissp_plugin_activate'); final class AI_Snippet_SEO_Pro { protected static $instance = null; private $supported_taxonomies = ['category','post_tag','product_cat','product_tag']; public static function get_instance(){ if(self::$instance===null){ self::$instance = new self(); } return self::$instance; } private function __construct(){ $this->define_constants(); $this->includes(); $this->init_hooks(); } private function define_constants(){ define('AISSP_VERSION','1.0.0'); define('AISSP_PATH', plugin_dir_path(__FILE__)); define('AISSP_URL', plugin_dir_url(__FILE__)); define('AISSP_SETTINGS_SLUG','aissp_settings'); } private function includes(){ require_once AISSP_PATH.'admin/settings-page.php'; require_once AISSP_PATH.'admin/meta-box.php'; require_once AISSP_PATH.'includes/helper-functions.php'; } private function init_hooks(){ add_filter('plugin_action_links_'.plugin_basename(__FILE__),[$this,'settings_link']); add_action('admin_menu',[$this,'register_admin_menu']); add_action('admin_init',[$this,'register_settings']); // Metabox add_action('add_meta_boxes',[ 'AISSP_Meta_Box','register_meta_boxes']); add_action('save_post',[ 'AISSP_Meta_Box','save_meta_box_data']); // Taxonomies foreach($this->supported_taxonomies as $tax){ add_action("{$tax}_edit_form_fields",[ 'AISSP_Meta_Box','render_term_edit_ui'],10,2); add_action("edited_{$tax}",[ 'AISSP_Meta_Box','save_term_edit_ui'],10,2); } // Bulk snippet for terms foreach($this->supported_taxonomies as $tax){ add_filter("bulk_actions-edit-{$tax}",[$this,'bulk_actions_terms']); add_filter("handle_bulk_actions-edit-{$tax}",[$this,'handle_bulk_terms'],10,3); } // Ajax snippet generation for single post add_action('wp_ajax_aissp_generate_snippet',[$this,'ajax_generate_snippet']); // Head meta add_action('wp_head',[$this,'inject_head_meta'],1); // Admin CSS/JS add_action('admin_enqueue_scripts',[$this,'enqueue_assets']); // Bulk + Filter for posts add_action('admin_init',[$this,'init_posttype_bulk_and_filter']); add_action('admin_init',[$this,'listing_columns_setup']); // Notices add_action('admin_notices',[$this,'show_bulk_notices']); } public function settings_link($links){ $settings_url = admin_url('admin.php?page=ai-snippet-seo-pro'); array_unshift($links,'Settings'); return $links; } public function register_admin_menu(){ add_menu_page( 'AI Snippet SEO Pro', 'AI Snippet SEO Pro', 'manage_options', 'ai-snippet-seo-pro', [$this,'render_settings_page'], 'dashicons-chart-line', 25 ); } public function render_settings_page(){ aissp_render_settings_page(); } public function register_settings(){ aissp_register_settings(); } public function enqueue_assets($hook){ $pages = ['post.php','post-new.php','term.php','edit-tags.php','admin.php?page=ai-snippet-seo-pro']; if(in_array($hook,$pages,true)){ wp_enqueue_style('aissp-admin-css',AISSP_URL.'admin/assets/css/admin.css',[],AISSP_VERSION); wp_enqueue_script('aissp-admin-js',AISSP_URL.'admin/assets/js/admin.js',['jquery'],AISSP_VERSION,true); $opts = get_option( AISSP_SETTINGS_SLUG, [] ); wp_localize_script( 'aissp-admin-js', 'AISSP_Ajax', // Aynı isim – çakışma yok, objeyi güncellersiniz [ 'ajaxurl' => admin_url( 'admin-ajax.php' ), // yine küçük “l” 'nonce' => wp_create_nonce( 'aissp_ajax_nonce' ), 'site_token' => $opts['site_token'] ?? '', 'rest_url' => esc_url_raw( rest_url( 'rankpilotai/v1' ) ), 'site_url' => home_url(), 'model' => $opts['model_choice'] ?? 'gpt-4-turbo', ] ); } } public function ajax_generate_snippet(){ check_ajax_referer('aissp_ajax_nonce','nonce'); $post_id = isset($_POST['post_id']) ? intval($_POST['post_id']) : 0; if(!$post_id) wp_send_json_error(['msg'=>'Invalid post ID']); try{ AISSP_Meta_Box::generate_ai_snippet_for_post($post_id,false); $fw = get_post_meta($post_id,'_aissp_focus_keyword',true); $ti = get_post_meta($post_id,'_aissp_seo_title',true); $de = get_post_meta($post_id,'_aissp_seo_description',true); $slug = get_post_field('post_name',$post_id); $sc = aissp_calc_score($fw,$ti,$de,$slug); wp_send_json_success([ // Eski isimler korunuyor ➜ başka yerleri bozmaz 'keyword' => $fw, 'title' => $ti, 'desc' => $de, // JS’in beklediği kısaltmalar 'kw' => $fw, 'ti' => $ti, 'de' => $de, 'slug' => $slug, 'score' => aissp_score_text( $sc['score'] ), 'color' => $sc['color'], ]); }catch(\Exception $ex){ wp_send_json_error(['msg'=>$ex->getMessage()]); } } // Bulk terms public function bulk_actions_terms($actions){ $actions['aissp_generate_seo'] = 'Generate with AI Snippet SEO Pro'; return $actions; } public function handle_bulk_terms($redirect,$action,$term_ids){ if($action!=='aissp_generate_seo') return $redirect; $opts = get_option(AISSP_SETTINGS_SLUG); if(empty($opts['site_token'])){ return add_query_arg('aissp_berror','notoken',$redirect); } $s=0;$f=0; foreach($term_ids as $tid){ try{ AISSP_Meta_Box::generate_ai_snippet_for_term($tid); $s++; }catch(\Exception $ex){ $f++; } usleep(200000); } return add_query_arg(['aissp_bsuccess'=>$s,'aissp_bfailed'=>$f],$redirect); } // Head meta public function inject_head_meta(){ if(is_singular()){ global $post; if(!$post) return; $opts = get_option(AISSP_SETTINGS_SLUG); $noindex=false; $pt = get_post_type($post->ID); if(isset($opts["index_{$pt}"]) && $opts["index_{$pt}"]==='no'){ $noindex=true; } if($noindex){ echo ''."\n"; } $fw=get_post_meta($post->ID,'_aissp_focus_keyword',true); $ti=get_post_meta($post->ID,'_aissp_seo_title',true); $de=get_post_meta($post->ID,'_aissp_seo_description',true); if($ti) echo ''.esc_html($ti).''."\n"; if($de) echo ''."\n"; if($fw) echo ''."\n"; } elseif(is_category()||is_tag()||is_tax()){ $term=get_queried_object(); if($term && isset($term->taxonomy)){ $opts=get_option(AISSP_SETTINGS_SLUG); $tax=$term->taxonomy; $noindex=false; if(isset($opts["index_{$tax}"]) && $opts["index_{$tax}"]==='no'){ $noindex=true; } if($noindex){ echo ''."\n"; } } } } // Bulk for posts public function init_posttype_bulk_and_filter(){ $pts=get_post_types(['public'=>true],'names'); foreach($pts as $pt){ add_filter("bulk_actions-edit-{$pt}",[$this,'bulk_actions_posts']); add_filter("handle_bulk_actions-edit-{$pt}",[$this,'handle_bulk_posts'],10,3); } add_action('restrict_manage_posts',[$this,'render_filter_posts']); add_filter('parse_query',[$this,'apply_filter_posts']); } public function bulk_actions_posts($acts){ $acts['aissp_generate_seo'] = 'Generate with AI Snippet SEO Pro'; return $acts; } public function handle_bulk_posts($redirect,$action,$post_ids){ if($action!=='aissp_generate_seo') return $redirect; $opts = get_option(AISSP_SETTINGS_SLUG); if(empty($opts['site_token'])){ return add_query_arg('aissp_berror','notoken',$redirect); } $s=0;$f=0; foreach($post_ids as $pid){ try{ AISSP_Meta_Box::generate_ai_snippet_for_post($pid,false); $s++; }catch(\Exception $ex){ $f++; } usleep(200000); } return add_query_arg(['aissp_bsuccess'=>$s,'aissp_bfailed'=>$f],$redirect); } // Filter public function render_filter_posts(){ global $pagenow; if($pagenow!=='edit.php') return; $v=isset($_GET['aissp_filter'])?sanitize_text_field($_GET['aissp_filter']):''; echo ''; } public function apply_filter_posts($query){ global $pagenow; if($pagenow!=='edit.php' || !is_admin() || !$query->is_main_query()) return; if(isset($_GET['aissp_filter'])){ $val=sanitize_text_field($_GET['aissp_filter']); $mq=[]; if($val==='haskw'){ $mq[]=['key'=>'_aissp_focus_keyword','compare'=>'EXISTS']; }elseif($val==='nokw'){ $mq[]=['key'=>'_aissp_focus_keyword','compare'=>'NOT EXISTS']; }elseif($val==='poor'){ $mq[]=['key'=>'_aissp_score','value'=>[0,66],'compare'=>'BETWEEN','type'=>'numeric']; }elseif($val==='fair'){ $mq[]=['key'=>'_aissp_score','value'=>[67,99],'compare'=>'BETWEEN','type'=>'numeric']; }elseif($val==='excel'){ $mq[]=['key'=>'_aissp_score','value'=>100,'compare'=>'=','type'=>'numeric']; } if(!empty($mq)){ $query->set('meta_query',$mq); } } } // Listing columns: Score public function listing_columns_setup(){ $pts=get_post_types(['public'=>true],'names'); foreach($pts as $pt){ add_filter("manage_{$pt}_posts_columns",[$this,'add_snippet_score_column']); add_action("manage_{$pt}_posts_custom_column",[$this,'render_snippet_score_column'],10,2); } } public function add_snippet_score_column($cols){ if(isset($cols['name'])){ $new=[]; foreach($cols as $k=>$v){ $new[$k]=$v; if($k==='name'){ $new['aissp_scorecol']='SEO Snippet Score'; } } return $new; } else { $new=[]; foreach($cols as $k=>$v){ $new[$k]=$v; if($k==='title'){ $new['aissp_scorecol']='SEO Snippet Score'; } } return $new; } } public function render_snippet_score_column($col,$post_id){ if($col==='aissp_scorecol'){ $val=get_post_meta($post_id,'_aissp_score',true); if($val==='') $val=0; $color='#dc3232'; if($val>=100){ $val=100;$color='#0091e0'; }elseif($val>=67){ $color='#ffab00'; } echo '' .(int)$val.' / 100'; } } // Notices (bulk success/fail) public function show_bulk_notices(){ if(isset($_GET['aissp_berror']) && $_GET['aissp_berror']==='notoken'){ echo '

AI SEO Error: No Site Token configured.

'; } if(isset($_GET['aissp_bsuccess']) || isset($_GET['aissp_bfailed'])){ $s=(int)($_GET['aissp_bsuccess']??0); $f=(int)($_GET['aissp_bfailed']??0); if($s>0){ echo '

AI SEO: Generated snippets for '.$s.' item(s).

'; } if($f>0){ echo '

AI SEO: Failed for '.$f.' item(s).

'; } } } } // Singleton function aissp(){ return AI_Snippet_SEO_Pro::get_instance(); } aissp(); https://rankpilotai.com/page-sitemap.xml 2025-07-21T17:44:13+00:00 https://rankpilotai.com/portfolio-sitemap.xml 2025-03-20T04:06:53+00:00 https://rankpilotai.com/product-sitemap.xml 2025-06-19T09:46:19+00:00