PluginProbe
Search Atlas SEO – OTTO AI SEO Automation for WordPress / trunk
Search Atlas SEO – OTTO AI SEO Automation for WordPress vtrunk
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 2.6.4 2.6.3 2.5.23 All 138 releases
metasync / google-index / google-index-init.php

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

141 lines 4.1 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 * @return Google_Index_Direct
52 */
53 function google_index_direct()
54 {
55 static $instance = null;
56
57 if ($instance === null) {
58 if (!class_exists('Google_Index_Direct')) {
59 error_log('MetaSync Google Index: Google_Index_Direct class not available.');
60 return null;
61 }
62 $instance = new Google_Index_Direct();
63 }
64
65 return $instance;
66 }
67
68 /**
69 * Convenience function to index a post
70 *
71 * @param int $post_id Post ID
72 * @param string $post_type Post type
73 * @param string $action Action (update, delete, status)
74 * @return array Result
75 */
76 function google_index_post($post_id, $post_type = 'post', $action = 'update')
77 {
78 return google_index_direct()->index_post($post_id, $post_type, $action);
79 }
80
81 /**
82 * Convenience function to index a URL
83 *
84 * @param string $url URL to index
85 * @param string $action Action (update, delete, status)
86 * @return array Result
87 */
88 function google_index_url($url, $action = 'update')
89 {
90 return google_index_direct()->index_url($url, $action);
91 }
92
93 /**
94 * Save Google Service Account configuration to database
95 *
96 * @param array $service_account_json Service account JSON configuration
97 * @return bool True on success, false on failure
98 */
99 function google_index_save_service_account($service_account_json)
100 {
101 return google_index_direct()->save_service_account_config($service_account_json);
102 }
103
104
105 // Initialize on WordPress init
106 add_action('init', 'google_index_direct_init');
107
108 /**
109 * Example usage in your plugin/theme:
110 *
111 * // Include this file to initialize the functionality
112 * require_once 'google-index/google-index-init.php';
113 *
114 * // SETUP: Configure service account via admin interface
115 * // 1. Go to WordPress Admin → MetaSync → Settings → General tab
116 * // 2. Scroll to "Google Index API" section
117 * // 3. Upload or paste your service account JSON and save settings
118 *
119 * // OR programmatically (one-time setup)
120 * $service_account = json_decode(file_get_contents('path/to/service-account.json'), true);
121 * google_index_save_service_account($service_account);
122 *
123 * // Basic usage - index a post manually
124 * $result = google_index_post(123, 'post', 'update');
125 *
126 * // Index a custom URL manually
127 * $result = google_index_url('https://yoursite.com/special-page/', 'update');
128 *
129 * // Check indexing status
130 * $result = google_index_url('https://yoursite.com/some-page/', 'status');
131 *
132 * // Get the main instance for advanced usage
133 * $google_index = google_index_direct();
134 * $test_results = $google_index->test_connection();
135 *
136 * // Auto-index posts on publish
137 * add_action('publish_post', function($post_id) {
138 * google_index_post($post_id, 'post', 'update');
139 * });
140 */
141