Changeset 1637819
- Timestamp:
- 04/14/2017 05:11:07 PM (9 years ago)
- Location:
- remote-post-swap/trunk
- Files:
-
- 10 edited
-
inc/admin/class-rps-admin.php (modified) (1 diff)
-
inc/class-rps-activator.php (modified) (1 diff)
-
inc/class-rps-base.php (modified) (1 diff)
-
inc/class-rps-deactivator.php (modified) (1 diff)
-
inc/class-rps-replace-wp.php (modified) (3 diffs)
-
inc/class-rps-retrieve-data.php (modified) (1 diff)
-
inc/class-rps.php (modified) (1 diff)
-
readme.txt (modified) (2 diffs)
-
remote-post-swap.php (modified) (1 diff)
-
uninstall.php (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
-
remote-post-swap/trunk/inc/admin/class-rps-admin.php
r1637292 r1637819 5 5 * 6 6 * @author Tyler Bailey 7 * @version 0. 5.07 * @version 0.6.0 8 8 * @package remote-post-swap 9 9 * @subpackage remote-post-swap/inc/admin -
remote-post-swap/trunk/inc/class-rps-activator.php
r1637292 r1637819 6 6 * 7 7 * @author Tyler Bailey 8 * @version 0. 5.08 * @version 0.6.0 9 9 * @package remote-post-swap 10 10 * @subpackage remote-post-swap/inc -
remote-post-swap/trunk/inc/class-rps-base.php
r1637292 r1637819 5 5 * 6 6 * @author Tyler Bailey 7 * @version 0. 5.07 * @version 0.6.0 8 8 * @package remote-post-swap 9 9 * @subpackage remote-post-swap/inc -
remote-post-swap/trunk/inc/class-rps-deactivator.php
r1637292 r1637819 6 6 * 7 7 * @author Tyler Bailey 8 * @version 0. 5.08 * @version 0.6.0 9 9 * @package remote-post-swap 10 10 * @subpackage remote-post-swap/inc -
remote-post-swap/trunk/inc/class-rps-replace-wp.php
r1637298 r1637819 5 5 * 6 6 * @author Tyler Bailey 7 * @version 0. 5.07 * @version 0.6.0 8 8 * @package remote-post-swap 9 9 * @subpackage remote-post-swap/inc … … 85 85 // Get the total post count queried 86 86 $post_count = count($posts); 87 $npc = 0; 87 // Array of already saved post IDs from the API 88 $rps_retrieve = array(); 88 89 89 90 foreach($posts as $post) { 90 $npc++;91 91 $rps_id = $this->rps_get_post_meta($post->ID); 92 92 93 93 if($rps_id) { 94 95 $post = $this->rps_swap_single_post($post, $rps_id); 96 94 $rps_retrieve[] = $rps_id; 95 } 96 } 97 98 // Number of items in the rps_retrieve array 99 $rps_count = count($rps_retrieve); 100 101 // Number of posts we need to query from the API 102 // Total number of posts from wp_query - number of posts in rps array 103 $num_posts = ($post_count - $rps_count); 104 105 // Default argument for API request 106 $rps_args = array( 107 'per_page' => $post_count 108 ); 109 110 if($num_posts > 0) { 111 if($rps_count > 0) { 112 $rps_args = array( 113 'per_page' => $num_posts, 114 'exclude' => $rps_retrieve 115 ); 116 117 $rps_saved = $this->rps_get_posts(null, array('include' => $rps_retrieve)); 97 118 } else { 98 99 $rpsp = $this->rps_get_posts(null, array('per_page' => $post_count)); 100 101 if($rpsp) { 102 // Set the array for the API posts 103 $rps_posts = array(); 104 105 // Set the new post count variable for the array 106 // Loop through returned API posts and assign new array data 107 foreach($rpsp as $rps_post) { 108 if($this->rps_ensure_unqiue_meta($rps_post->id)) { 109 $rps_posts[$npc]['post_id'] = $rps_post->id; 110 $rps_posts[$npc]['post_content'] = $this->rps_adjust_media_urls($rps_post->content->rendered); 111 $rps_posts[$npc]['post_title'] = $rps_post->title->rendered; 112 $rps_posts[$npc]['post_date'] = $rps_post->date; 113 $rps_posts[$npc]['post_excerpt'] = $rps_post->excerpt->rendered; 114 } 115 } 116 117 // Reset the new post count variable for the second array 118 // Loop through original post object and replace data with returned API data 119 $post->post_title = $rps_posts[$npc]['post_title']; 120 $post->post_content = $rps_posts[$npc]['post_content']; 121 $post->post_date = $rps_posts[$npc]['post_date']; 122 $post->post_excerpt = $rps_posts[$npc]['post_excerpt']; 123 124 update_post_meta($post->ID, $this->rps_meta, $rps_posts[$npc]['post_id']); 125 } 119 $rps_args = array( 120 'per_page' => $num_posts, 121 ); 122 } 123 } else { 124 $rps_args = array( 125 'include' => $rps_retrieve 126 ); 127 } 128 129 // Get the posts from the API 130 $rpsp = $this->rps_get_posts(null, $rps_args); 131 132 // If we got new posts + retrieved saved posts, merge the array 133 if(isset($rps_saved) && !empty($rps_saved)) 134 $rpsp = array_merge($rps_saved, $rpsp); 135 136 // If we have any new posts at all 137 if($rpsp && !empty($rpsp)) { 138 // Set the array for the API posts 139 $rps_posts = array(); 140 141 // Set the "New Post Counter" variable 142 $npc = 0; 143 144 // Loop through returned API posts and assign new array data 145 foreach($rpsp as $rps_post) { 146 147 $rps_posts[$npc]['post_id'] = $rps_post->id; 148 $rps_posts[$npc]['post_content'] = $this->rps_adjust_media_urls($rps_post->content->rendered); 149 $rps_posts[$npc]['post_title'] = $rps_post->title->rendered; 150 $rps_posts[$npc]['post_date'] = $rps_post->date; 151 $rps_posts[$npc]['post_excerpt'] = $rps_post->excerpt->rendered; 152 153 $npc++; 154 } 155 156 // Set the "Original Post Counter" variable 157 $opc = 0; 158 foreach($posts as $post) { 159 160 // Loop through original post object and replace data with returned API data 161 $post->post_title = $rps_posts[$opc]['post_title']; 162 $post->post_content = $rps_posts[$opc]['post_content']; 163 $post->post_date = $rps_posts[$opc]['post_date']; 164 $post->post_excerpt = $rps_posts[$opc]['post_excerpt']; 165 166 if($this->rps_ensure_unqiue_meta($rps_posts[$opc]['post_id'])) 167 update_post_meta($post->ID, $this->rps_meta, $rps_posts[$opc]['post_id']); 168 169 $opc++; 126 170 } 127 171 } … … 172 216 */ 173 217 private function rps_ensure_unqiue_meta($rps_id) { 218 219 $rps_id = (int) $rps_id; 220 174 221 $args = array( 175 'posts_per_page' => -1, 176 'meta_key' => $this->rps_meta, 177 'meta_value' => $rps_id 222 'posts_per_page' => 1, 223 'meta_query' => array( 224 array( 225 'key' => $this->rps_meta, 226 'value' => $rps_id 227 ) 228 ), 229 'fields' => 'ids' 178 230 ); 231 179 232 $rpsq = new WP_Query( $args ); 180 233 181 if($rpsq->have_posts()) { 234 $rpsq_arr = $rpsq->posts; 235 236 if(!empty($rpsq_arr)) { 182 237 return false; 183 238 } 239 240 wp_reset_query(); 184 241 185 242 return true; -
remote-post-swap/trunk/inc/class-rps-retrieve-data.php
r1637292 r1637819 5 5 * 6 6 * @author Tyler Bailey 7 * @version 0. 5.07 * @version 0.6.0 8 8 * @package remote-post-swap 9 9 * @subpackage remote-post-swap/inc -
remote-post-swap/trunk/inc/class-rps.php
r1637292 r1637819 5 5 * 6 6 * @author Tyler Bailey 7 * @version 0. 5.07 * @version 0.6.0 8 8 * @package remote-post-swap 9 9 * @subpackage remote-post-swap/inc -
remote-post-swap/trunk/readme.txt
r1637292 r1637819 4 4 Requires at least: 4.7.0 5 5 Tested up to: 4.7.3 6 Stable tag: 0.5.0 6 Stable tag: 0.6.0 7 License: GPLv2 or later 8 License URI: http://www.gnu.org/licenses/gpl-2.0.html 7 9 8 10 Swap local development post data out with live/remote post data on the fly … … 35 37 == Changelog == 36 38 39 = 0.6.0 = 40 * Re-wrote the replace-wp class to only make a maximum of 2 API calls per loop. (Performance enhancement) 41 37 42 = 0.5.0 = 38 43 * Initial Release -
remote-post-swap/trunk/remote-post-swap.php
r1637292 r1637819 17 17 * Plugin URI: http://tylerb.me/plugins/remote-post-swap.zip 18 18 * Description: Swap local development post data out with live/remote post data on the fly 19 * Version: 0. 5.019 * Version: 0.6.0 20 20 * Author: Tyler Bailey 21 21 * Author URI: http://tylerb.me -
remote-post-swap/trunk/uninstall.php
r1637297 r1637819 3 3 * Fired when the plugin is uninstalled. 4 4 * 5 * @link http://tylerb.me6 * @since 0.5.05 * @link http://tylerb.me 6 * @since 0.5.0 7 7 * @package rps 8 8 */ … … 11 11 if ( ! defined( 'WP_UNINSTALL_PLUGIN' ) ) { 12 12 exit; 13 } else { 14 delete_post_meta_by_key( 'rps_post_id' ); 13 15 } 14 15 delete_post_meta_by_key( 'rps_post_id' );
Note: See TracChangeset
for help on using the changeset viewer.