index_post($post_id, $post_type, $action); } /** * Convenience function to index a URL * * @param string $url URL to index * @param string $action Action (update, delete, status) * @return array Result */ function google_index_url($url, $action = 'update') { return google_index_direct()->index_url($url, $action); } /** * Save Google Service Account configuration to database * * @param array $service_account_json Service account JSON configuration * @return bool True on success, false on failure */ function google_index_save_service_account($service_account_json) { return google_index_direct()->save_service_account_config($service_account_json); } // Initialize on WordPress init add_action('init', 'google_index_direct_init'); /** * Example usage in your plugin/theme: * * // Include this file to initialize the functionality * require_once 'google-index/google-index-init.php'; * * // SETUP: Configure service account via admin interface * // 1. Go to WordPress Admin → MetaSync → Settings → General tab * // 2. Scroll to "Google Index API" section * // 3. Upload or paste your service account JSON and save settings * * // OR programmatically (one-time setup) * $service_account = json_decode(file_get_contents('path/to/service-account.json'), true); * google_index_save_service_account($service_account); * * // Basic usage - index a post manually * $result = google_index_post(123, 'post', 'update'); * * // Index a custom URL manually * $result = google_index_url('https://yoursite.com/special-page/', 'update'); * * // Check indexing status * $result = google_index_url('https://yoursite.com/some-page/', 'status'); * * // Get the main instance for advanced usage * $google_index = google_index_direct(); * $test_results = $google_index->test_connection(); * * // Auto-index posts on publish * add_action('publish_post', function($post_id) { * google_index_post($post_id, 'post', 'update'); * }); */