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

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

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