PluginProbe
Search Atlas SEO – OTTO AI SEO Automation for WordPress / 2.7.0
Search Atlas SEO – OTTO AI SEO Automation for WordPress v2.7.0
2.7.1 2.7.2 2.7.0 2.6.26 2.6.25 2.6.24 2.6.23 2.6.22 2.6.21 2.6.20 2.6.19 2.6.18 2.6.17 2.6.16 2.6.15 2.6.14 2.6.13 2.6.12 2.6.11 2.6.10 2.6.9 2.6.8 2.6.7 2.6.6 2.6.5 All 141 releases
metasync / google-index / google-index-init.php

google-index-init.php in Search Atlas SEO – OTTO AI SEO Automation for WordPress 2.7.0, at google-index/google-index-init.php

150 lines 4.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 /**
4 * Google Index API - Initialization & Entry Point
5 *
6 * This file initializes and provides the main API for the Google Index Direct
7 * implementation. It serves as the primary entry point for the functionality.
8 *
9 * @package GoogleIndexDirect
10 * @version 1.0.0
11 */
12
13 // Prevent direct access
14 if (!defined('ABSPATH')) {
15 exit;
16 }
17
18 // Define constants for this module
19 define('GOOGLE_INDEX_DIRECT_VERSION', '1.0.0');
20 define('GOOGLE_INDEX_DIRECT_PATH', __DIR__);
21 define('GOOGLE_INDEX_DIRECT_URL', plugin_dir_url(__FILE__));
22
23 /**
24 * Initialize Google Index API
25 *
26 * Call this function to load and initialize the Google Index functionality
27 */
28 function google_index_direct_init()
29 {
30 // Load the main class
31 if (file_exists(GOOGLE_INDEX_DIRECT_PATH . '/class-google-index-direct.php')) {
32 require_once GOOGLE_INDEX_DIRECT_PATH . '/class-google-index-direct.php';
33 } else {
34 error_log('MetaSync Google Index: class-google-index-direct.php not found at ' . GOOGLE_INDEX_DIRECT_PATH . '/class-google-index-direct.php');
35 return;
36 }
37
38 // Load admin interface if in admin area
39 if (is_admin()) {
40 if (file_exists(GOOGLE_INDEX_DIRECT_PATH . '/class-google-index-admin.php')) {
41 require_once GOOGLE_INDEX_DIRECT_PATH . '/class-google-index-admin.php';
42 } else {
43 error_log('MetaSync Google Index: class-google-index-admin.php not found at ' . GOOGLE_INDEX_DIRECT_PATH . '/class-google-index-admin.php');
44 }
45 }
46 }
47
48 /**
49 * Get Google Index Direct instance
50 *
51 * Returns null when the class could not be loaded — callers that reached this
52 * before google_index_direct_init() ran, or on an install where the class file
53 * is missing, get null rather than a fatal.
54 *
55 * @return Google_Index_Direct|null
56 */
57 function google_index_direct()
58 {
59 static $instance = null;
60
61 if ($instance === null) {
62 if (!class_exists('Google_Index_Direct')) {
63 error_log('MetaSync Google Index: Google_Index_Direct class not available.');
64 return null;
65 }
66 $instance = new Google_Index_Direct();
67 }
68
69 return $instance;
70 }
71
72 /**
73 * Convenience function to index a post
74 *
75 * @param int $post_id Post ID
76 * @param string $post_type Post type
77 * @param string $action Action (update, delete, status)
78 * @return array Result
79 */
80 function google_index_post($post_id, $post_type = 'post', $action = 'update')
81 {
82 return google_index_direct()->index_post($post_id, $post_type, $action);
83 }
84
85 /**
86 * Convenience function to index a URL
87 *
88 * @param string $url URL to index
89 * @param string $action Action (update, delete, status)
90 * @return array Result
91 */
92 function google_index_url($url, $action = 'update')
93 {
94 return google_index_direct()->index_url($url, $action);
95 }
96
97 /**
98 * Save Google Service Account configuration to database
99 *
100 * @param array $service_account_json Service account JSON configuration
101 * @return bool True on success, false on failure
102 */
103 function google_index_save_service_account($service_account_json)
104 {
105 $instance = google_index_direct();
106 if (!$instance) {
107 return false;
108 }
109
110 return $instance->save_service_account_config($service_account_json);
111 }
112
113
114 // Initialize on WordPress init
115 add_action('init', 'google_index_direct_init');
116
117 /**
118 * Example usage in your plugin/theme:
119 *
120 * // Include this file to initialize the functionality
121 * require_once 'google-index/google-index-init.php';
122 *
123 * // SETUP: Configure service account via admin interface
124 * // 1. Go to WordPress Admin → MetaSync → Settings → General tab
125 * // 2. Scroll to "Google Index API" section
126 * // 3. Upload or paste your service account JSON and save settings
127 *
128 * // OR programmatically (one-time setup)
129 * $service_account = json_decode(file_get_contents('path/to/service-account.json'), true);
130 * google_index_save_service_account($service_account);
131 *
132 * // Basic usage - index a post manually
133 * $result = google_index_post(123, 'post', 'update');
134 *
135 * // Index a custom URL manually
136 * $result = google_index_url('https://yoursite.com/special-page/', 'update');
137 *
138 * // Check indexing status
139 * $result = google_index_url('https://yoursite.com/some-page/', 'status');
140 *
141 * // Get the main instance for advanced usage
142 * $google_index = google_index_direct();
143 * $test_results = $google_index->test_connection();
144 *
145 * // Auto-index posts on publish
146 * add_action('publish_post', function($post_id) {
147 * google_index_post($post_id, 'post', 'update');
148 * });
149 */
150