1+ <?php
2+
3+ namespace Cbx \Careertoolkit ;
4+
5+ /**
6+ * Class Helper
7+ * @package Cbx\Careertoolkit
8+ * @since 1.0.0
9+ */
10+ class Helper {
11+
12+ /**
13+ * Load textdomain
14+ *
15+ * @since 1.0.0
16+ */
17+ public function load_plugin_textdomain () {
18+ load_plugin_textdomain ( 'cbxcareertoolkit ' , false , CBXCAREER_TOOLKIT_ROOT_PATH . 'languages/ ' );
19+ }//end method load_plugin_textdomain
20+
21+ /**
22+ * Custom update checker implemented
23+ *
24+ * @param $transient
25+ *
26+ * @return mixed
27+ */
28+ public function pre_set_site_transient_update_plugins ( $ transient ) {
29+ // Ensure the transient is set
30+ if ( empty ( $ transient ->checked ) ) {
31+ return $ transient ;
32+ }
33+
34+ $ plugin_slug = 'cbxcareertoolkit ' ;
35+ $ plugin_file = 'cbxcareertoolkit/cbxcareertoolkit.php ' ;
36+
37+ if ( isset ( $ transient ->response [ $ plugin_file ] ) ) {
38+ return $ transient ;
39+ }
40+
41+ if ( ! function_exists ( 'get_plugins ' ) ) {
42+ require_once ABSPATH . 'wp-admin/includes/plugin.php ' ;
43+ }
44+
45+ $ url = 'https://comforthrm.com/product_updates.json ' ; // Replace with your remote JSON file URL
46+
47+ // Fetch the remote JSON file
48+ $ response = wp_remote_get ( $ url );
49+
50+ if ( is_wp_error ( $ response ) || wp_remote_retrieve_response_code ( $ response ) != 200 ) {
51+ return $ transient ;
52+ }
53+
54+ $ data = json_decode ( wp_remote_retrieve_body ( $ response ), true );// Set true for associative array, false for object
55+
56+
57+ if ( ! isset ( $ data ['cbxcareertoolkit ' ] ) ) {
58+ return $ transient ;
59+ }
60+
61+ $ remote_data = $ data ['cbxcareertoolkit ' ];
62+
63+ $ plugin_url = isset ( $ remote_data ['url ' ] ) ? $ remote_data ['url ' ] : '' ;
64+ $ package_url = isset ( $ remote_data ['api_url ' ] ) ? $ remote_data ['api_url ' ] : false ;
65+
66+ $ remote_version = isset ( $ remote_data ['new_version ' ] ) ? sanitize_text_field ( $ remote_data ['new_version ' ] ) : '' ;
67+
68+ if ( $ remote_version != '' && version_compare ( $ remote_version , $ transient ->checked [ $ plugin_file ], '> ' ) ) {
69+ $ transient ->response [ $ plugin_file ] = (object ) [
70+ 'slug ' => $ plugin_slug ,
71+ 'new_version ' => $ remote_version ,
72+ 'url ' => $ plugin_url ,
73+ 'package ' => $ package_url , // Link to the new version
74+ ];
75+ }
76+
77+ return $ transient ;
78+ }//end method pre_set_site_transient_update_plugins
79+
80+ public function plugin_info ( $ res , $ action , $ args ) {
81+ // Plugin slug
82+ $ plugin_slug = 'cbxcareertoolkit ' ; // Replace with your plugin slug
83+
84+ // Ensure we're checking the correct plugin
85+ if ( $ action !== 'plugin_information ' || $ args ->slug !== $ plugin_slug ) {
86+ return $ res ;
87+ }
88+
89+ // Fetch detailed plugin information
90+ $ response = wp_remote_get ( 'https://comforthrm.com/product_updates.json ' ); // Replace with your API URL
91+
92+ if ( is_wp_error ( $ response ) || wp_remote_retrieve_response_code ( $ response ) != 200 ) {
93+ return $ res ;
94+ }
95+
96+ $ data = json_decode ( wp_remote_retrieve_body ( $ response ), true );
97+ if ( ! isset ( $ data [ $ plugin_slug ] ) ) {
98+ return $ res ;
99+ }
100+
101+ $ remote_data = $ data [ $ plugin_slug ];
102+ $ package_url = isset ( $ remote_data ['api_url ' ] ) ? $ remote_data ['api_url ' ] : false ;
103+
104+ // Build the plugin info response
105+ return (object ) [
106+ 'name ' => isset ( $ remote_data ['name ' ] ) ? sanitize_text_field ( $ remote_data ['name ' ] ) : 'CBX Careertoolkit ' ,
107+ 'slug ' => $ plugin_slug ,
108+ 'version ' => isset ( $ remote_data ['new_version ' ] ) ? sanitize_text_field ( $ remote_data ['new_version ' ] ) : '' ,
109+ 'author ' => isset ( $ remote_data ['author ' ] ) ? sanitize_text_field ( $ remote_data ['author ' ] ) : '' ,
110+ 'homepage ' => isset ( $ remote_data ['url ' ] ) ? $ remote_data ['url ' ] : '' ,
111+ 'requires ' => isset ( $ remote_data ['requires ' ] ) ? sanitize_text_field ( $ remote_data ['requires ' ] ) : '' ,
112+ 'tested ' => isset ( $ remote_data ['tested ' ] ) ? sanitize_text_field ( $ remote_data ['tested ' ] ) : '' ,
113+ 'download_link ' => $ package_url ,
114+ 'sections ' => [
115+ 'description ' => isset ( $ remote_data ['description ' ] ) ? wp_kses_post ( $ remote_data ['description ' ] ) : '' ,
116+ 'changelog ' => isset ( $ remote_data ['changelog ' ] ) ? wp_kses_post ( $ remote_data ['changelog ' ] ) : '' ,
117+ ],
118+ ];
119+
120+ }//end method plugin_info
121+ }//end class Helper
0 commit comments