Changeset 2470907
- Timestamp:
- 02/08/2021 03:21:37 PM (5 years ago)
- Location:
- hellowoofy-com
- Files:
-
- 17 added
- 1 edited
-
tags/1.0.2 (added)
-
tags/1.0.2/LICENSE (added)
-
tags/1.0.2/assets (added)
-
tags/1.0.2/assets/css (added)
-
tags/1.0.2/assets/css/admin.css (added)
-
tags/1.0.2/assets/fonts (added)
-
tags/1.0.2/assets/fonts/ProximaNova-Regular.eot (added)
-
tags/1.0.2/assets/fonts/ProximaNova-Regular.ttf (added)
-
tags/1.0.2/assets/fonts/ProximaNova-Regular.woff (added)
-
tags/1.0.2/assets/img (added)
-
tags/1.0.2/assets/img/icon.png (added)
-
tags/1.0.2/assets/img/image.png (added)
-
tags/1.0.2/assets/js (added)
-
tags/1.0.2/assets/js/admin.js (added)
-
tags/1.0.2/hellowoofy-com.php (added)
-
tags/1.0.2/index.php (added)
-
tags/1.0.2/readme.txt (added)
-
trunk/hellowoofy-com.php (modified) (8 diffs)
Legend:
- Unmodified
- Added
- Removed
-
hellowoofy-com/trunk/hellowoofy-com.php
r2445216 r2470907 4 4 * Plugin URI: https://hellowoofy.com/hellowoofy-wordpress-plugin/ 5 5 * Description: Create marketing content automatically using data science. 6 * Version: 1.0. 16 * Version: 1.0.2 7 7 * Author: HelloWoofy.com 8 8 * Author URI: https://hellowoofy.com … … 30 30 */ 31 31 32 if (!defined('ABSPATH')) {33 die;34 }35 36 32 class WoofyIntegration 37 33 { … … 47 43 } 48 44 49 45 /** 46 * Plugin settings 47 */ 50 48 public function woofy_settings() 51 49 { … … 74 72 } 75 73 74 /** 75 * Route for creating posts 76 */ 76 77 public function woofy_register_route() 77 78 { … … 127 128 } 128 129 130 /** 131 * @param $url 132 * @param null $post_id 133 * @return string|WP_Error 134 * Function for attaching feature image to post 135 */ 136 private function woofy_insert_attachment($image_url, $post_id = null, $user_id) { 137 if ( ! function_exists( 'media_handle_upload' ) 138 && user_can($user_id, 'edit_posts')) 139 { 140 require_once ABSPATH . 'wp-admin/includes/media.php'; 141 require_once ABSPATH . 'wp-admin/includes/file.php'; 142 require_once ABSPATH . 'wp-admin/includes/image.php'; 143 144 $img_id = media_sideload_image($image_url, $post_id, null, 'id'); 145 set_post_thumbnail($post_id, $img_id); 146 147 if( is_wp_error($img_id) ){ 148 return new WP_Error( 400, __( "Image wasn't uploaded", "woofy" ) ); 149 } 150 return wp_get_attachment_image_src($img_id); 151 } else { 152 return new WP_Error( 400, __( "Check 'media_handle_upload' failed", "woofy" ) ); 153 } 154 } 155 129 156 public function woofy_set_cat_func() 130 157 { 131 158 $args_for_send = array('category', 'post_tag'); 159 // Added to DB 132 160 $categories = get_terms($args_for_send, 'orderby=name&hide_empty=0'); 133 161 $categories_for_send = []; … … 156 184 $key_decode = base64_decode($unique_user_key); 157 185 $user_id = stristr($key_decode, '=', true); 186 $image_url = $request->get_param('journalPostFeaturedImage'); 158 187 159 188 // create array for Post … … 184 213 // Added to DB 185 214 $post_id = wp_insert_post(wp_slash($post_data)); 215 216 if( is_wp_error($post_id) ){ 217 return $post_id->get_error_message(); 218 } 219 186 220 wp_set_object_terms($post_id, $post_category, 'category'); 187 221 wp_set_object_terms($post_id, $post_tags, 'post_tag'); 222 223 if ($image_url) { 224 $thumbnail = $this->woofy_insert_attachment($image_url, $post_id, $user_id); 225 }else { 226 $thumbnail = "Image wasn't set in request"; 227 } 228 229 if (is_wp_error($thumbnail)) { 230 return $thumbnail->get_error_messages(); 231 } 188 232 189 233 return $result = array( … … 191 235 'post_id' => $post_id, 192 236 'post_url' => get_permalink($post_id), 237 'thumbnail' => $thumbnail ? $thumbnail : '' 193 238 ); 194 239 }
Note: See TracChangeset
for help on using the changeset viewer.