Hide Title - Version 1.0.6

Version Description

  • Tested New Update Functions for future releases
Download this release

Release Info

Developer dojodigital
Plugin Icon wp plugin Hide Title
Version 1.0.6
Comparing to
See all releases

Code changes from version 1.0.4 to 1.0.6

Files changed (4) hide show
  1. dojo-digital-hide-title.php +185 -182
  2. readme.txt +100 -91
  3. uninstall.php +0 -5
  4. wp-updates-plugin.php +116 -0
dojo-digital-hide-title.php CHANGED
@@ -1,182 +1,185 @@
1
- <?php
2
- /*
3
- Plugin Name: Hide Title
4
- Plugin URI: http://dojodigital.com
5
- Description: Allows authors to hide the title tag on single pages and posts via the edit post screen.
6
- Version: 1.0.4
7
- Author: Brandon Kraft & Randall Runnels
8
- Author URI: http://dojodigital.com
9
- */
10
-
11
- if ( !class_exists( 'DojoDigitalHideTitle' ) ) {
12
-
13
- class DojoDigitalHideTitle {
14
-
15
- private $slug = 'dojodigital_toggle_title';
16
- private $selector = '.entry-title';
17
- private $title;
18
- private $afterHead = false;
19
-
20
- /**
21
- * PHP 5 Constructor
22
- */
23
- function __construct(){
24
-
25
- add_action( 'add_meta_boxes', array( $this, 'add_box' ) );
26
- add_action( 'save_post', array( $this, 'on_save' ) );
27
- add_action( 'delete_post', array( $this, 'on_delete' ) );
28
- add_action( 'wp_head', array( $this, 'head_insert' ), 3000 );
29
- add_action( 'the_title', array( $this, 'wrap_title' ) );
30
- add_action( 'wp_enqueue_scripts', array( $this, 'load_scripts' ) );
31
-
32
- } // __construct()
33
-
34
-
35
- private function is_hidden( ){
36
-
37
- if( is_singular() ){
38
-
39
- global $post;
40
-
41
- $toggle = get_post_meta( $post->ID, $this->slug, true );
42
-
43
- if( (bool) $toggle ){
44
- return true;
45
- } else {
46
- return false;
47
- }
48
-
49
- } else {
50
- return false;
51
- }
52
-
53
- } // is_hidden()
54
-
55
-
56
- public function head_insert(){
57
-
58
- if( $this->is_hidden() ){ ?>
59
- <!-- Dojo Digital Hide Title -->
60
- <script type="text/javascript">
61
- jQuery(document).ready(function($){
62
-
63
- if( $('<?php echo $this->selector; ?>').length != 0 ) {
64
- $('<?php echo $this->selector; ?> span.<?php echo $this->slug; ?>').parents('<?php echo $this->selector; ?>:first').hide();
65
- } else {
66
- $('h1 span.<?php echo $this->slug; ?>').parents('h1:first').hide();
67
- $('h2 span.<?php echo $this->slug; ?>').parents('h2:first').hide();
68
- }
69
-
70
- });
71
- </script>
72
- <noscript><style type="text/css"> <?php echo $this->selector; ?> { display:none !important; }</style></noscript>
73
- <!-- END Dojo Digital Hide Title -->
74
-
75
- <?php }
76
-
77
- // Indicate that the header has run so we can hopefully prevent adding span tags to the meta attributes, etc.
78
- $this->afterHead = true;
79
-
80
- } // head_insert()
81
-
82
-
83
- public function add_box(){
84
-
85
- $posttypes = array( 'post', 'page' );
86
-
87
- foreach ( $posttypes as $posttype ){
88
- add_meta_box( $this->slug, 'Hide Title', array( $this, 'build_box' ), $posttype, 'side' );
89
- }
90
-
91
- } // add_box()
92
-
93
-
94
- public function build_box( $post ){
95
-
96
- $value = get_post_meta( $post->ID, $this->slug, true );
97
-
98
- $checked = '';
99
-
100
- if( (bool) $value ){ $checked = ' checked="checked"'; }
101
-
102
- wp_nonce_field( $this->slug . '_dononce', $this->slug . '_noncename' );
103
-
104
- ?>
105
- <label><input type="checkbox" name="<?php echo $this->slug; ?>" <?php echo $checked; ?> /> Hide the title on singular page views.</label>
106
- <?php
107
-
108
- } // build_box()
109
-
110
-
111
- public function wrap_title( $content ){
112
-
113
- if( $this->is_hidden() && $content == $this->title && $this->afterHead ){
114
- $content = '<span class="' . $this->slug . '">' . $content . '</span>';
115
- }
116
-
117
- return $content;
118
-
119
- } // wrap_title()
120
-
121
-
122
- public function load_scripts(){
123
-
124
-
125
- // Grab the title early in case it's overridden later by extra loops.
126
- global $post;
127
- $this->title = $post->post_title;
128
-
129
- if( $this->is_hidden() ){
130
- wp_enqueue_script( 'jquery' );
131
-
132
- }
133
-
134
- } // load_scripts()
135
-
136
-
137
- public function on_save( $postID ){
138
-
139
- if ( ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
140
- || !isset( $_POST[ $this->slug . '_noncename' ] )
141
- || !wp_verify_nonce( $_POST[ $this->slug . '_noncename' ], $this->slug . '_dononce' ) ) {
142
- return $postID;
143
- }
144
-
145
- $old = get_post_meta( $postID, $this->slug, true );
146
- $new = $_POST[ $this->slug ] ;
147
-
148
- if( $old ){
149
- if ( is_null( $new ) ){
150
- delete_post_meta( $postID, $this->slug );
151
- } else {
152
- update_post_meta( $postID, $this->slug, $new, $old );
153
- }
154
- } elseif ( !is_null( $new ) ){
155
- add_post_meta( $postID, $this->slug, $new, true );
156
- }
157
-
158
- return $postID;
159
-
160
- } // on_save()
161
-
162
-
163
- public function on_delete( $postID ){
164
- delete_post_meta( $postID, $this->slug );
165
- return $postID;
166
- } // on_delete()
167
-
168
-
169
- public function set_selector( $selector ){
170
-
171
- if( isset( $selector ) && is_string( $selector ) ){
172
- $this->selector = $selector;
173
- }
174
-
175
- } // set_selector()
176
-
177
-
178
- } // DojoDigitalHideTitle
179
-
180
- $DojoDigitalHideTitle = new DojoDigitalHideTitle;
181
-
182
- } // !class_exists( 'DojoDigitalHideTitle' )
 
 
 
1
+ <?php
2
+ /*
3
+ Plugin Name: Hide Title
4
+ Plugin URI: http://dojodigital.com
5
+ Description: Allows authors to hide the title tag on single pages and posts via the edit post screen.
6
+ Version: 1.0.6
7
+ Author: Dojo Digital
8
+ Author URI: http://dojodigital.com
9
+ */
10
+
11
+ if ( !class_exists( 'DojoDigitalHideTitle' ) ) {
12
+
13
+ class DojoDigitalHideTitle {
14
+
15
+ private $slug = 'dojodigital_toggle_title';
16
+ private $selector = '.entry-title';
17
+ private $title;
18
+ private $afterHead = false;
19
+
20
+ /**
21
+ * PHP 5 Constructor
22
+ */
23
+ function __construct(){
24
+
25
+ add_action( 'add_meta_boxes', array( $this, 'add_box' ) );
26
+ add_action( 'save_post', array( $this, 'on_save' ) );
27
+ add_action( 'delete_post', array( $this, 'on_delete' ) );
28
+ add_action( 'wp_head', array( $this, 'head_insert' ), 3000 );
29
+ add_action( 'the_title', array( $this, 'wrap_title' ) );
30
+ add_action( 'wp_enqueue_scripts', array( $this, 'load_scripts' ) );
31
+
32
+ } // __construct()
33
+
34
+
35
+ private function is_hidden( ){
36
+
37
+ if( is_singular() ){
38
+
39
+ global $post;
40
+
41
+ $toggle = get_post_meta( $post->ID, $this->slug, true );
42
+
43
+ if( (bool) $toggle ){
44
+ return true;
45
+ } else {
46
+ return false;
47
+ }
48
+
49
+ } else {
50
+ return false;
51
+ }
52
+
53
+ } // is_hidden()
54
+
55
+
56
+ public function head_insert(){
57
+
58
+ if( $this->is_hidden() ){ ?>
59
+ <!-- Dojo Digital Hide Title -->
60
+ <script type="text/javascript">
61
+ jQuery(document).ready(function($){
62
+
63
+ if( $('<?php echo $this->selector; ?>').length != 0 ) {
64
+ $('<?php echo $this->selector; ?> span.<?php echo $this->slug; ?>').parents('<?php echo $this->selector; ?>:first').hide();
65
+ } else {
66
+ $('h1 span.<?php echo $this->slug; ?>').parents('h1:first').hide();
67
+ $('h2 span.<?php echo $this->slug; ?>').parents('h2:first').hide();
68
+ }
69
+
70
+ });
71
+ </script>
72
+ <noscript><style type="text/css"> <?php echo $this->selector; ?> { display:none !important; }</style></noscript>
73
+ <!-- END Dojo Digital Hide Title -->
74
+
75
+ <?php }
76
+
77
+ // Indicate that the header has run so we can hopefully prevent adding span tags to the meta attributes, etc.
78
+ $this->afterHead = true;
79
+
80
+ } // head_insert()
81
+
82
+
83
+ public function add_box(){
84
+
85
+ $posttypes = array( 'post', 'page' );
86
+
87
+ foreach ( $posttypes as $posttype ){
88
+ add_meta_box( $this->slug, 'Hide Title', array( $this, 'build_box' ), $posttype, 'side' );
89
+ }
90
+
91
+ } // add_box()
92
+
93
+
94
+ public function build_box( $post ){
95
+
96
+ $value = get_post_meta( $post->ID, $this->slug, true );
97
+
98
+ $checked = '';
99
+
100
+ if( (bool) $value ){ $checked = ' checked="checked"'; }
101
+
102
+ wp_nonce_field( $this->slug . '_dononce', $this->slug . '_noncename' );
103
+
104
+ ?>
105
+ <label><input type="checkbox" name="<?php echo $this->slug; ?>" <?php echo $checked; ?> /> Hide the title on singular page views.</label>
106
+ <?php
107
+
108
+ } // build_box()
109
+
110
+
111
+ public function wrap_title( $content ){
112
+
113
+ if( $this->is_hidden() && $content == $this->title && $this->afterHead ){
114
+ $content = '<span class="' . $this->slug . '">' . $content . '</span>';
115
+ }
116
+
117
+ return $content;
118
+
119
+ } // wrap_title()
120
+
121
+
122
+ public function load_scripts(){
123
+
124
+
125
+ // Grab the title early in case it's overridden later by extra loops.
126
+ global $post;
127
+ $this->title = $post->post_title;
128
+
129
+ if( $this->is_hidden() ){
130
+ wp_enqueue_script( 'jquery' );
131
+
132
+ }
133
+
134
+ } // load_scripts()
135
+
136
+
137
+ public function on_save( $postID ){
138
+
139
+ if ( ( defined('DOING_AUTOSAVE') && DOING_AUTOSAVE )
140
+ || !isset( $_POST[ $this->slug . '_noncename' ] )
141
+ || !wp_verify_nonce( $_POST[ $this->slug . '_noncename' ], $this->slug . '_dononce' ) ) {
142
+ return $postID;
143
+ }
144
+
145
+ $old = get_post_meta( $postID, $this->slug, true );
146
+ $new = $_POST[ $this->slug ] ;
147
+
148
+ if( $old ){
149
+ if ( is_null( $new ) ){
150
+ delete_post_meta( $postID, $this->slug );
151
+ } else {
152
+ update_post_meta( $postID, $this->slug, $new, $old );
153
+ }
154
+ } elseif ( !is_null( $new ) ){
155
+ add_post_meta( $postID, $this->slug, $new, true );
156
+ }
157
+
158
+ return $postID;
159
+
160
+ } // on_save()
161
+
162
+
163
+ public function on_delete( $postID ){
164
+ delete_post_meta( $postID, $this->slug );
165
+ return $postID;
166
+ } // on_delete()
167
+
168
+
169
+ public function set_selector( $selector ){
170
+
171
+ if( isset( $selector ) && is_string( $selector ) ){
172
+ $this->selector = $selector;
173
+ }
174
+
175
+ } // set_selector()
176
+
177
+
178
+ } // DojoDigitalHideTitle
179
+
180
+ $DojoDigitalHideTitle = new DojoDigitalHideTitle;
181
+
182
+ } // !class_exists( 'DojoDigitalHideTitle' )
183
+
184
+ require_once('wp-updates-plugin.php');
185
+ new WPUpdatesPluginUpdater_2059( 'http://wp-updates.com/api/2/plugin', plugin_basename(__FILE__));
readme.txt CHANGED
@@ -1,91 +1,100 @@
1
- === Hide Title ===
2
-
3
- Contributors: dojodigital, kraftbj
4
- Plugin Name: Hide Title
5
- Plugin URI: http://hidetitle.dojodigital.com/
6
- Tags: wp, title
7
- Author URI: http://dojodigital.com/
8
- Author: Dojo Digital
9
- Requires at least: 3.2
10
- Tested up to: 4.2
11
- Stable tag: 1.0.4
12
- Version: 1.0.4
13
-
14
- Allows authors to hide the title on single pages and posts via the edit post screen.
15
-
16
- == Description ==
17
-
18
- This plugin allows the author of a post or page to hide the title and it's containing HTML element from the single view ( is_singular() ).
19
-
20
- == Installation ==
21
-
22
- 1. Upload the `hide-title` folder to the `/wp-content/plugins/` directory
23
- 1. Activate the plugin through the 'Plugins' menu in WordPress
24
-
25
- == Screenshots ==
26
-
27
- 1. This Meta Box will be added to the Edit screen for pages & posts
28
-
29
- == Changelog ==
30
-
31
- = 1.0.4 =
32
-
33
- * Now compatible with latest versions of WordPress
34
- * PHP 4 is no longer supported.
35
-
36
- = 1.0.3 =
37
-
38
- * Fixed a jQuery bug which prevented fallbacks in the case that the selector was not found.
39
-
40
- = 1.0.2 =
41
-
42
- * Added logic to flag when wp_head has run to prevent changes being made to the title in the &gt;head&lt; area.
43
- * Fixed a bug that caused multiple meta field entries.
44
-
45
- = 1.0.1 =
46
-
47
- * Changed the jQuery to use a less brute force method of hiding the title.
48
- * Added a set_selector() method to allow end-users to specify the css selector to hide.
49
-
50
- == Upgrade Notice ==
51
-
52
- = 1.0.4 =
53
- * Fixes errors on latest versions of WordPress.
54
-
55
- = 1.0.3 =
56
-
57
- * This version fixes a jQuery bug which prevented fallbacks in the case that the selector was not found.
58
-
59
- = 1.0.2 =
60
-
61
- * This version flags when wp_head has run to prevent changes being made to the title in the <head> area and fixed a glitch reported by several users that caused multiple meta entries to be created.
62
-
63
- = 1.0.1 =
64
-
65
- * This version uses a less brute force method of hiding the title by trying to find and hide `.entry-title` before looking for the title inside of `h1` or `h2` tags and hiding them. This version also adds a method for theme editors to change the selector from the default `.entry-title` to whatever they want to use.
66
-
67
- == Frequently Asked Questions ==
68
-
69
-
70
- = I upgraded to 1.0.2 and the plugin stopped working. Why? =
71
-
72
- It is possible that your theme does not have the wp_head function in it's header.php file. In general all themes are suppose to have it, and version 1.0.2 looks for it to prevent adding bad code to the `<head>` area of the page. If you have access to your theme file simply add `<?php wp_head(); ?>` to header.php just before the `</head>` tag. If not, this plugin will no longer be compatible with your theme.
73
-
74
- = Hey! This plugin is hiding things I don't want hidden! =
75
-
76
- By default this plugin looks for the `.entry-title` class and hides it. If it doesn't find it it will look for any `h1` or `h2` elements that contain the title and hide them instead. To change the default `.entry-title` selector to something that makes more sense to you, add the following code to the functions.php file of your current theme:
77
-
78
- `global $DojoDigitalHideTitle;
79
- // Be sure to replace ".your-selector" with your selector!
80
- $DojoDigitalHideTitle->set_selector('.your-selector');`
81
-
82
- As noted in the comments, you'll need to replace the string `.your-selector` with the css selector you'd like hidden. It can be any valid css selector such as `h1`, `.myclass`, `#myid`, etc. I recommend using a class or id to avoid accidentally hiding unforeseen elements.
83
-
84
- = I don't want to edit my theme files, can't you just add an option page? =
85
-
86
- I could, but I'd like to avoid adding Yet Another Options Page if I can. If enough people request it though, I'll go ahead and bite the bullet.
87
-
88
- = Who is the author of this plugin anyway? =
89
-
90
- This plugin was originally was developed by Randall Runnels of Dojo Digital. In March 2015, the plugin was not compatible with the latest version of WordPress. After finding the problem, Brandon Kraft reached out with a solution, but didn't hear a response. He contacted the Plugins team at WordPress.org with an offer to assume development to bring it up date. The plugins team reached out and either recieved the approval of Randall, did not hear back at all, or the e-mail bounced.
91
-
 
 
 
 
 
 
 
 
 
1
+ === Hide Title ===
2
+
3
+ Contributors: dojodigital, kraftbj
4
+ Plugin Name: Hide Title
5
+ Plugin URI: http://hidetitle.dojodigital.com/
6
+ Tags: wp, title
7
+ Author URI: http://dojodigital.com/
8
+ Author: Dojo Digital
9
+ Requires at least: 3.2
10
+ Tested up to: 5.0
11
+ Stable tag: 1.0.6
12
+ Version: 1.0.6
13
+
14
+ Allows authors to hide the title on single pages and posts via the edit post screen.
15
+
16
+ == Description ==
17
+
18
+ This plugin allows the author of a post or page to hide the title and it's containing HTML element from the single view ( is_singular() ).
19
+
20
+ == Installation ==
21
+
22
+ 1. Upload the `hide-title` folder to the `/wp-content/plugins/` directory
23
+ 1. Activate the plugin through the 'Plugins' menu in WordPress
24
+
25
+ == Screenshots ==
26
+
27
+ 1. This Meta Box will be added to the Edit screen for pages & posts
28
+
29
+ == Changelog ==
30
+
31
+ = 1.0.6 =
32
+
33
+ * Tested New Update Functions for future releases
34
+
35
+ = 1.0.5 =
36
+
37
+ * Fixed Deletion Error
38
+ * Added WP-Updater Support
39
+
40
+ = 1.0.4 =
41
+
42
+ * Now compatible with latest versions of WordPress
43
+ * PHP 4 is no longer supported.
44
+
45
+ = 1.0.3 =
46
+
47
+ * Fixed a jQuery bug which prevented fallbacks in the case that the selector was not found.
48
+
49
+ = 1.0.2 =
50
+
51
+ * Added logic to flag when wp_head has run to prevent changes being made to the title in the &gt;head&lt; area.
52
+ * Fixed a bug that caused multiple meta field entries.
53
+
54
+ = 1.0.1 =
55
+
56
+ * Changed the jQuery to use a less brute force method of hiding the title.
57
+ * Added a set_selector() method to allow end-users to specify the css selector to hide.
58
+
59
+ == Upgrade Notice ==
60
+
61
+ = 1.0.4 =
62
+ * Fixes errors on latest versions of WordPress.
63
+
64
+ = 1.0.3 =
65
+
66
+ * This version fixes a jQuery bug which prevented fallbacks in the case that the selector was not found.
67
+
68
+ = 1.0.2 =
69
+
70
+ * This version flags when wp_head has run to prevent changes being made to the title in the <head> area and fixed a glitch reported by several users that caused multiple meta entries to be created.
71
+
72
+ = 1.0.1 =
73
+
74
+ * This version uses a less brute force method of hiding the title by trying to find and hide `.entry-title` before looking for the title inside of `h1` or `h2` tags and hiding them. This version also adds a method for theme editors to change the selector from the default `.entry-title` to whatever they want to use.
75
+
76
+ == Frequently Asked Questions ==
77
+
78
+
79
+ = I upgraded to 1.0.2 and the plugin stopped working. Why? =
80
+
81
+ It is possible that your theme does not have the wp_head function in it's header.php file. In general all themes are suppose to have it, and version 1.0.2 looks for it to prevent adding bad code to the `<head>` area of the page. If you have access to your theme file simply add `<?php wp_head(); ?>` to header.php just before the `</head>` tag. If not, this plugin will no longer be compatible with your theme.
82
+
83
+ = Hey! This plugin is hiding things I don't want hidden! =
84
+
85
+ By default this plugin looks for the `.entry-title` class and hides it. If it doesn't find it it will look for any `h1` or `h2` elements that contain the title and hide them instead. To change the default `.entry-title` selector to something that makes more sense to you, add the following code to the functions.php file of your current theme:
86
+
87
+ `global $DojoDigitalHideTitle;
88
+ // Be sure to replace ".your-selector" with your selector!
89
+ $DojoDigitalHideTitle->set_selector('.your-selector');`
90
+
91
+ As noted in the comments, you'll need to replace the string `.your-selector` with the css selector you'd like hidden. It can be any valid css selector such as `h1`, `.myclass`, `#myid`, etc. I recommend using a class or id to avoid accidentally hiding unforeseen elements.
92
+
93
+ = I don't want to edit my theme files, can't you just add an option page? =
94
+
95
+ I could, but I'd like to avoid adding Yet Another Options Page if I can. If enough people request it though, I'll go ahead and bite the bullet.
96
+
97
+ = Who is the author of this plugin anyway? =
98
+
99
+ This plugin was originally was developed by Randall Runnels of Dojo Digital. In March 2015, the plugin was not compatible with the latest version of WordPress. After finding the problem, Brandon Kraft reached out with a solution, but didn't hear a response. He contacted the Plugins team at WordPress.org with an offer to assume development to bring it up date. The plugins team reached out and either recieved the approval of Randall, did not hear back at all, or the e-mail bounced.
100
+
uninstall.php DELETED
@@ -1,5 +0,0 @@
1
- <?php
2
-
3
- global $wpdb;
4
-
5
- $wpdb->query( $wpdb->prepare( 'DELETE FROM ' . $wpdb->postmeta . ' WHERE meta_key="dojodigital_toggle_title"' ) );
 
 
 
 
 
wp-updates-plugin.php ADDED
@@ -0,0 +1,116 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ <?php
2
+ /*
3
+ WPUpdates Plugin Updater Class
4
+ http://wp-updates.com
5
+ v2.0
6
+
7
+ Example Usage:
8
+ require_once('wp-updates-plugin.php');
9
+ new WPUpdatesPluginUpdater_2059( 'http://wp-updates.com/api/2/plugin', plugin_basename(__FILE__) );
10
+ */
11
+
12
+ if( !class_exists('WPUpdatesPluginUpdater_2059') ) {
13
+ class WPUpdatesPluginUpdater_2059 {
14
+
15
+ var $api_url;
16
+ var $plugin_id = 2059;
17
+ var $plugin_path;
18
+ var $plugin_slug;
19
+ var $license_key;
20
+
21
+ function __construct( $api_url, $plugin_path, $license_key = null ) {
22
+ $this->api_url = $api_url;
23
+ $this->plugin_path = $plugin_path;
24
+ $this->license_key = $license_key;
25
+ if(strstr($plugin_path, '/')) list ($t1, $t2) = explode('/', $plugin_path);
26
+ else $t2 = $plugin_path;
27
+ $this->plugin_slug = str_replace('.php', '', $t2);
28
+
29
+ add_filter( 'pre_set_site_transient_update_plugins', array(&$this, 'check_for_update') );
30
+ add_filter( 'plugins_api', array(&$this, 'plugin_api_call'), 10, 3 );
31
+
32
+ // This is for testing only!
33
+ //set_site_transient( 'update_plugins', null );
34
+
35
+ // Show which variables are being requested when query plugin API
36
+ //add_filter( 'plugins_api_result', array(&$this, 'debug_result'), 10, 3 );
37
+ }
38
+
39
+ function check_for_update( $transient ) {
40
+ if(empty($transient->checked)) return $transient;
41
+
42
+ $request_args = array(
43
+ 'id' => $this->plugin_id,
44
+ 'slug' => $this->plugin_slug,
45
+ 'version' => $transient->checked[$this->plugin_path]
46
+ );
47
+ if ($this->license_key) $request_args['license'] = $this->license_key;
48
+
49
+ $request_string = $this->prepare_request( 'update_check', $request_args );
50
+ $raw_response = wp_remote_post( $this->api_url, $request_string );
51
+
52
+ $response = null;
53
+ if( !is_wp_error($raw_response) && ($raw_response['response']['code'] == 200) )
54
+ $response = unserialize($raw_response['body']);
55
+
56
+ if( is_object($response) && !empty($response) ) {
57
+ // Feed the update data into WP updater
58
+ $transient->response[$this->plugin_path] = $response;
59
+ return $transient;
60
+ }
61
+
62
+ // Check to make sure there is not a similarly named plugin in the wordpress.org repository
63
+ if ( isset( $transient->response[$this->plugin_path] ) ) {
64
+ if ( strpos( $transient->response[$this->plugin_path]->package, 'wordpress.org' ) !== false ) {
65
+ unset($transient->response[$this->plugin_path]);
66
+ }
67
+ }
68
+
69
+ return $transient;
70
+ }
71
+
72
+ function plugin_api_call( $def, $action, $args ) {
73
+ if( !isset($args->slug) || $args->slug != $this->plugin_slug ) return $def;
74
+
75
+ $plugin_info = get_site_transient('update_plugins');
76
+ $request_args = array(
77
+ 'id' => $this->plugin_id,
78
+ 'slug' => $this->plugin_slug,
79
+ 'version' => (isset($plugin_info->checked)) ? $plugin_info->checked[$this->plugin_path] : 0 // Current version
80
+ );
81
+ if ($this->license_key) $request_args['license'] = $this->license_key;
82
+
83
+ $request_string = $this->prepare_request( $action, $request_args );
84
+ $raw_response = wp_remote_post( $this->api_url, $request_string );
85
+
86
+ if( is_wp_error($raw_response) ){
87
+ $res = new WP_Error('plugins_api_failed', __('An Unexpected HTTP Error occurred during the API request.</p> <p><a href="?" onclick="document.location.reload(); return false;">Try again</a>'), $raw_response->get_error_message());
88
+ } else {
89
+ $res = unserialize($raw_response['body']);
90
+ if ($res === false)
91
+ $res = new WP_Error('plugins_api_failed', __('An unknown error occurred'), $raw_response['body']);
92
+ }
93
+
94
+ return $res;
95
+ }
96
+
97
+ function prepare_request( $action, $args ) {
98
+ global $wp_version;
99
+
100
+ return array(
101
+ 'body' => array(
102
+ 'action' => $action,
103
+ 'request' => serialize($args),
104
+ 'api-key' => md5(home_url())
105
+ ),
106
+ 'user-agent' => 'WordPress/'. $wp_version .'; '. home_url()
107
+ );
108
+ }
109
+
110
+ function debug_result( $res, $action, $args ) {
111
+ echo '<pre>'.print_r($res,true).'</pre>';
112
+ return $res;
113
+ }
114
+
115
+ }
116
+ }