@@ -68,4 +68,104 @@ public static function active_plugin() {
68
68
new CBXWPMigrationsTable ( $ texonomy_migration_files , CBXTAXONOMY_PLUGIN_NAME );
69
69
}//end method active plugin
70
70
71
+ /**
72
+ * Custom update checker implemented
73
+ *
74
+ * @param $transient
75
+ *
76
+ * @return mixed
77
+ */
78
+ public function pre_set_site_transient_update_plugins ( $ transient ) {
79
+ // Ensure the transient is set
80
+ if ( empty ( $ transient ->checked ) ) {
81
+ return $ transient ;
82
+ }
83
+
84
+ $ plugin_slug = 'cbxtaxonomy ' ;
85
+ $ plugin_file = 'cbxtaxonomy/cbxtaxonomy.php ' ;
86
+
87
+ if ( isset ( $ transient ->response [ $ plugin_file ] ) ) {
88
+ return $ transient ;
89
+ }
90
+
91
+ if ( ! function_exists ( 'get_plugins ' ) ) {
92
+ require_once ABSPATH . 'wp-admin/includes/plugin.php ' ;
93
+ }
94
+
95
+ $ url = 'https://comforthrm.com/product_updates.json ' ; // Replace with your remote JSON file URL
96
+
97
+ // Fetch the remote JSON file
98
+ $ response = wp_remote_get ( $ url );
99
+
100
+ if ( is_wp_error ( $ response ) || wp_remote_retrieve_response_code ( $ response ) != 200 ) {
101
+ return $ transient ;
102
+ }
103
+
104
+ $ data = json_decode ( wp_remote_retrieve_body ( $ response ), true );// Set true for associative array, false for object
105
+
106
+
107
+ if ( ! isset ( $ data ['cbxtaxonomy ' ] ) ) {
108
+ return $ transient ;
109
+ }
110
+
111
+ $ remote_data = $ data ['cbxtaxonomy ' ];
112
+
113
+ $ plugin_url = isset ( $ remote_data ['url ' ] ) ? $ remote_data ['url ' ] : '' ;
114
+ $ package_url = isset ( $ remote_data ['api_url ' ] ) ? $ remote_data ['api_url ' ] : false ;
115
+
116
+ $ remote_version = isset ( $ remote_data ['new_version ' ] ) ? sanitize_text_field ( $ remote_data ['new_version ' ] ) : '' ;
117
+
118
+ if ( $ remote_version != '' && version_compare ( $ remote_version , $ transient ->checked [ $ plugin_file ], '> ' ) ) {
119
+ $ transient ->response [ $ plugin_file ] = (object ) [
120
+ 'slug ' => $ plugin_slug ,
121
+ 'new_version ' => $ remote_version ,
122
+ 'url ' => $ plugin_url ,
123
+ 'package ' => $ package_url , // Link to the new version
124
+ ];
125
+ }
126
+
127
+ return $ transient ;
128
+ }//end method pre_set_site_transient_update_plugins
129
+
130
+ public function plugin_info ( $ res , $ action , $ args ) {
131
+ // Plugin slug
132
+ $ plugin_slug = 'cbxtaxonomy ' ; // Replace with your plugin slug
133
+
134
+ // Ensure we're checking the correct plugin
135
+ if ( $ action !== 'plugin_information ' || $ args ->slug !== $ plugin_slug ) {
136
+ return $ res ;
137
+ }
138
+
139
+ // Fetch detailed plugin information
140
+ $ response = wp_remote_get ( 'https://comforthrm.com/product_updates.json ' ); // Replace with your API URL
141
+
142
+ if ( is_wp_error ( $ response ) || wp_remote_retrieve_response_code ( $ response ) != 200 ) {
143
+ return $ res ;
144
+ }
145
+
146
+ $ data = json_decode ( wp_remote_retrieve_body ( $ response ), true );
147
+ if ( ! isset ( $ data [ $ plugin_slug ] ) ) {
148
+ return $ res ;
149
+ }
150
+
151
+ $ remote_data = $ data [ $ plugin_slug ];
152
+ $ package_url = isset ( $ remote_data ['api_url ' ] ) ? $ remote_data ['api_url ' ] : false ;
153
+
154
+ // Build the plugin info response
155
+ return (object ) [
156
+ 'name ' => isset ( $ remote_data ['name ' ] ) ? sanitize_text_field ( $ remote_data ['name ' ] ) : 'CBX Texonomy ' ,
157
+ 'slug ' => $ plugin_slug ,
158
+ 'version ' => isset ( $ remote_data ['new_version ' ] ) ? sanitize_text_field ( $ remote_data ['new_version ' ] ) : '' ,
159
+ 'author ' => isset ( $ remote_data ['author ' ] ) ? sanitize_text_field ( $ remote_data ['author ' ] ) : '' ,
160
+ 'homepage ' => isset ( $ remote_data ['url ' ] ) ? $ remote_data ['url ' ] : '' ,
161
+ 'requires ' => isset ( $ remote_data ['requires ' ] ) ? sanitize_text_field ( $ remote_data ['requires ' ] ) : '' ,
162
+ 'tested ' => isset ( $ remote_data ['tested ' ] ) ? sanitize_text_field ( $ remote_data ['tested ' ] ) : '' ,
163
+ 'download_link ' => $ package_url ,
164
+ 'sections ' => [
165
+ 'description ' => isset ( $ remote_data ['description ' ] ) ? wp_kses_post ( $ remote_data ['description ' ] ) : '' ,
166
+ 'changelog ' => isset ( $ remote_data ['changelog ' ] ) ? wp_kses_post ( $ remote_data ['changelog ' ] ) : '' ,
167
+ ],
168
+ ];
169
+
170
+ }//end method plugin_info
71
171
}//end class CBXTaxonomyHelper
0 commit comments