Changeset 3158668
- Timestamp:
- 09/27/2024 10:12:04 AM (18 months ago)
- Location:
- quickcreator
- Files:
-
- 5 edited
- 4 copied
-
tags/0.0.7 (copied) (copied from quickcreator/trunk)
-
tags/0.0.7/includes/quickcreator/class-content-importer.php (modified) (25 diffs)
-
tags/0.0.7/includes/quickcreator/class-quickcreator.php (copied) (copied from quickcreator/trunk/includes/quickcreator/class-quickcreator.php) (3 diffs)
-
tags/0.0.7/quickcreator.php (copied) (copied from quickcreator/trunk/quickcreator.php) (1 diff)
-
tags/0.0.7/readme.txt (copied) (copied from quickcreator/trunk/readme.txt) (1 diff)
-
trunk/includes/quickcreator/class-content-importer.php (modified) (25 diffs)
-
trunk/includes/quickcreator/class-quickcreator.php (modified) (3 diffs)
-
trunk/quickcreator.php (modified) (1 diff)
-
trunk/readme.txt (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
-
quickcreator/tags/0.0.7/includes/quickcreator/class-content-importer.php
r3142565 r3158668 1 1 <?php 2 2 3 /** 3 4 * Object that handle importing content from: … … 18 19 * Object that imports data from different sources into WordPress. 19 20 */ 20 class Content_Importer { 21 class Content_Importer 22 { 21 23 22 24 /** … … 31 33 * Basic construct. 32 34 */ 33 public function __construct() { 35 public function __construct() 36 { 34 37 $this->content_parser = new Parsers_Controller(); 35 38 } … … 43 46 * @return int|WP_Error 44 47 */ 45 public function save_data_into_database( $content, $args = array()) { 48 public function save_data_into_database($content, $args = array()) 49 { 46 50 $user = get_users()[0]; 47 wp_set_current_user( $user->ID, $user->data->display_name);48 if ( 'elementor' === $args['filter']) {51 wp_set_current_user($user->ID, $user->data->display_name); 52 if ('elementor' === $args['filter']) { 49 53 $if_elementor_is_active = quickcreator_check_if_plugins_is_active('elementor/elementor.php'); 50 54 if ($if_elementor_is_active) { 51 55 $rawContent = ""; 52 56 } 53 } else if ( 'raw' !== $args['filter']) {54 $rawContent = $this->content_parser->parse_content( $content);57 } else if ('raw' !== $args['filter']) { 58 $rawContent = $this->content_parser->parse_content($content); 55 59 } else { 56 60 $this->content_parser->choose_parser(); 57 61 $rawContent = $content; 58 62 } 59 $title = isset( $args['post_title'] ) && strlen( $args['post_title']) > 0 ? $args['post_title'] : $this->content_parser->return_title();63 $title = isset($args['post_title']) && strlen($args['post_title']) > 0 ? $args['post_title'] : $this->content_parser->return_title(); 60 64 61 65 $data = array( … … 64 68 ); 65 69 66 if ( isset( $args['post_id'] ) && $args['post_id'] > 0) {70 if (isset($args['post_id']) && $args['post_id'] > 0) { 67 71 68 72 $provided_post_id = $args['post_id']; … … 75 79 } 76 80 77 $this->resolve_post_author( $args, $data);78 $this->resolve_post_status( $args, $data);79 $this->resolve_post_type( $args, $data);80 $this->resolve_post_permalink( $args, $data);81 $this->resolve_post_category( $args, $data);82 $this->resolve_post_tags( $args, $data);83 $this->resolve_post_meta_details( $args, $data);84 $this->resolve_post_excerpt( $args, $data);85 $this->resolve_post_parent( $args, $data);86 87 if ( isset( $post ) && 'published' === $post['post_status']) {81 $this->resolve_post_author($args, $data); 82 $this->resolve_post_status($args, $data); 83 $this->resolve_post_type($args, $data); 84 $this->resolve_post_permalink($args, $data); 85 $this->resolve_post_category($args, $data); 86 $this->resolve_post_tags($args, $data); 87 $this->resolve_post_meta_details($args, $data); 88 $this->resolve_post_excerpt($args, $data); 89 $this->resolve_post_parent($args, $data); 90 91 if (isset($post) && 'published' === $post['post_status']) { 88 92 // WordPress set current date as default and we do not want to change publication date. 89 93 $data['post_date'] = $post['post_date']; 90 94 } else { 91 $this->resolve_post_date( $args, $data);92 } 93 94 $post_id = wp_insert_post( $data, true);95 96 if ( ! is_wp_error( $post_id ) && isset( $args['draft_id'] )) {97 update_post_meta( $post_id, 'quickcreator_draft_id', $args['draft_id']);98 update_post_meta( $post_id, 'quickcreator_permalink_hash', isset( $args['permalink_hash'] ) ? $args['permalink_hash'] : '');99 update_post_meta( $post_id, 'quickcreator_keywords', $args['keywords']);100 update_post_meta( $post_id, 'quickcreator_location', $args['location']);101 update_post_meta( $post_id, 'quickcreator_scrape_ready', true);102 update_post_meta( $post_id, 'quickcreator_last_post_update', round( microtime( true ) * 1000 ));103 update_post_meta( $post_id, 'quickcreator_last_post_update_direction', 'from Quickcreator to WordPress');104 } 105 106 $this->resove_post_meta_after_insert_post( $post_id, $args);107 108 if ( 'elementor' === $args['filter']) {95 $this->resolve_post_date($args, $data); 96 } 97 98 $post_id = wp_insert_post($data, true); 99 100 if (! is_wp_error($post_id) && isset($args['draft_id'])) { 101 update_post_meta($post_id, 'quickcreator_draft_id', $args['draft_id']); 102 update_post_meta($post_id, 'quickcreator_permalink_hash', isset($args['permalink_hash']) ? $args['permalink_hash'] : ''); 103 update_post_meta($post_id, 'quickcreator_keywords', $args['keywords']); 104 update_post_meta($post_id, 'quickcreator_location', $args['location']); 105 update_post_meta($post_id, 'quickcreator_scrape_ready', true); 106 update_post_meta($post_id, 'quickcreator_last_post_update', round(microtime(true) * 1000)); 107 update_post_meta($post_id, 'quickcreator_last_post_update_direction', 'from Quickcreator to WordPress'); 108 } 109 110 $this->resove_post_meta_after_insert_post($post_id, $args); 111 112 if ('elementor' === $args['filter']) { 109 113 $if_elementor_is_active = quickcreator_check_if_plugins_is_active('elementor/elementor.php'); 110 114 if ($if_elementor_is_active) { 111 \Elementor\Plugin::$instance->documents->ajax_save( [ 112 'editor_post_id' => $post_id, 113 'status' => $data["post_status"], 114 'elements' => $content['elements'], 115 'settings' => $content['settings'], 116 ] ); 117 } 118 } else { 119 $this->content_parser->run_after_post_insert_actions( $post_id ); 115 \Elementor\Plugin::$instance->documents->ajax_save([ 116 'editor_post_id' => $post_id, 117 'status' => $data["post_status"], 118 'elements' => $content['elements'], 119 'settings' => $content['settings'], 120 ]); 121 if (isset($args['meta_input']) && isset($args['meta_input']['_elementor_template_type']) && "kit" === $args['meta_input']['_elementor_template_type']) { 122 $kits_manager = \Elementor\Plugin::$instance->kits_manager; 123 update_option($kits_manager::OPTION_PREVIOUS, $kits_manager->get_active_id()); 124 update_option($kits_manager::OPTION_ACTIVE, $post_id); 125 } 126 } 127 } else { 128 $this->content_parser->run_after_post_insert_actions($post_id); 120 129 } 121 130 return $post_id; … … 129 138 * @return array URL to image in media library. 130 139 */ 131 public function upload_img_to_media_library( $image_url, $image_alt ) { 132 $image_data = $this->content_parser->upload_img_to_media_library( $image_url, $image_alt); 140 public function upload_img_to_media_library($image_url, $image_alt) 141 { 142 $image_data = $this->content_parser->upload_img_to_media_library($image_url, $image_alt); 133 143 $image_url = $image_data['url']; 134 144 $image_id = $image_data['id']; … … 152 162 * @return void 153 163 */ 154 private function resolve_post_author( $args, &$data ) { 155 156 if ( isset( $args['post_author'] ) && '' !== $args['post_author'] ) { 164 private function resolve_post_author($args, &$data) 165 { 166 167 if (isset($args['post_author']) && '' !== $args['post_author']) { 157 168 158 169 $value = $args['post_author']; 159 170 160 if ( is_numeric( $value ) && $value > 0) {171 if (is_numeric($value) && $value > 0) { 161 172 $data['post_author'] = $value; 162 173 } else { 163 $data['post_author'] = $this->get_user_id_by_login( $value);164 } 165 } else { 166 $default = Quickcreator()->get_quickcreator_settings()->get_option( 'content-importer', 'default_post_author', false);167 168 if ( false !== $default) {174 $data['post_author'] = $this->get_user_id_by_login($value); 175 } 176 } else { 177 $default = Quickcreator()->get_quickcreator_settings()->get_option('content-importer', 'default_post_author', false); 178 179 if (false !== $default) { 169 180 $data['post_author'] = $default; 170 181 } 171 182 } 172 183 } 173 184 174 185 /** 175 186 * Fill $data array with proper attribute for post_excerpt or leave empty to fill default. … … 179 190 * @return void 180 191 */ 181 private function resolve_post_excerpt( $args, &$data) { 182 if ( isset( $args['post_excerpt'] ) && '' !== $args['post_excerpt'] ) { 192 private function resolve_post_excerpt($args, &$data) 193 { 194 if (isset($args['post_excerpt']) && '' !== $args['post_excerpt']) { 183 195 $data['post_excerpt'] = $args['post_excerpt']; 184 } 196 } 185 197 } 186 198 … … 192 204 * @return void 193 205 */ 194 private function resolve_post_status( $args, &$data ) { 195 196 $allowed_statuses = array( 'publish', 'draft', 'pending', 'future', 'private' ); 197 198 if ( isset( $args['post_status'] ) && '' !== $args['post_status'] && in_array( $args['post_status'], $allowed_statuses, true ) ) { 206 private function resolve_post_status($args, &$data) 207 { 208 209 $allowed_statuses = array('publish', 'draft', 'pending', 'future', 'private'); 210 211 if (isset($args['post_status']) && '' !== $args['post_status'] && in_array($args['post_status'], $allowed_statuses, true)) { 199 212 $data['post_status'] = $args['post_status']; 200 213 } else { 201 $default = Quickcreatorblog::get_instance()->get_quickcreator_settings()->get_option( 'content-importer', 'default_post_status', false);202 203 if ( false !== $default) {214 $default = Quickcreatorblog::get_instance()->get_quickcreator_settings()->get_option('content-importer', 'default_post_status', false); 215 216 if (false !== $default) { 204 217 $data['post_status'] = $default; 205 218 } … … 214 227 * @return void 215 228 */ 216 private function resolve_post_type( $args, &$data ) { 229 private function resolve_post_type($args, &$data) 230 { 217 231 218 232 $allowed_post_types = quickcreator_return_supported_post_types(); 219 233 220 if ( isset( $args['post_type'] ) && '' !== $args['post_type'] && in_array( $args['post_type'], $allowed_post_types, true )) {234 if (isset($args['post_type']) && '' !== $args['post_type'] && in_array($args['post_type'], $allowed_post_types, true)) { 221 235 $data['post_type'] = $args['post_type']; 222 236 } else { … … 232 246 * @return void 233 247 */ 234 private function resolve_post_date( $args, &$data ) { 235 236 if ( isset( $args['post_date'] ) && strtotime( $args['post_date'] ) > time() ) { 237 $data['post_date'] = gmdate( 'Y-m-d H:i:s', strtotime( $args['post_date'] ) ); 248 private function resolve_post_date($args, &$data) 249 { 250 251 if (isset($args['post_date']) && strtotime($args['post_date']) > time()) { 252 $data['post_date'] = gmdate('Y-m-d H:i:s', strtotime($args['post_date'])); 238 253 } 239 254 } … … 246 261 * @return void 247 262 */ 248 private function resolve_post_parent($args, &$data) { 249 250 if ( isset( $args['post_parent'] ) && '' !== $args['post_parent'] ) { 263 private function resolve_post_parent($args, &$data) 264 { 265 266 if (isset($args['post_parent']) && '' !== $args['post_parent']) { 251 267 $data['post_parent'] = $args['post_parent']; 252 268 } … … 261 277 * @return void 262 278 */ 263 private function resolve_post_permalink( $args, &$data ) { 264 265 if ( isset( $args['post_name'] ) && '' !== $args['post_name'] ) { 279 private function resolve_post_permalink($args, &$data) 280 { 281 282 if (isset($args['post_name']) && '' !== $args['post_name']) { 266 283 $data['post_name'] = $args['post_name']; 267 284 } … … 275 292 * @return void 276 293 */ 277 private function resolve_post_category( $args, &$data ) { 278 279 if ( isset( $args['post_category'] ) && is_array( $args['post_category'] ) && ! empty( $args['post_category'] ) ) { 294 private function resolve_post_category($args, &$data) 295 { 296 297 if (isset($args['post_category']) && is_array($args['post_category']) && ! empty($args['post_category'])) { 280 298 281 299 $categories = array(); 282 foreach ( $args['post_category'] as $category) {300 foreach ($args['post_category'] as $category) { 283 301 $categories[] = $category; 284 302 } … … 286 304 $data['post_category'] = $categories; 287 305 } else { 288 $default = Quickcreatorblog::get_instance()->get_quickcreator_settings()->get_option( 'content-importer', 'default_category', false);289 290 if ( false !== $default) {291 $data['post_category'] = array( $default);306 $default = Quickcreatorblog::get_instance()->get_quickcreator_settings()->get_option('content-importer', 'default_category', false); 307 308 if (false !== $default) { 309 $data['post_category'] = array($default); 292 310 } 293 311 } … … 301 319 * @return void 302 320 */ 303 private function resolve_post_tags( $args, &$data ) { 304 305 if ( isset( $args['post_tags'] ) && is_array( $args['post_tags'] ) && count( $args['post_tags'] ) > 0 ) { 321 private function resolve_post_tags($args, &$data) 322 { 323 324 if (isset($args['post_tags']) && is_array($args['post_tags']) && count($args['post_tags']) > 0) { 306 325 307 326 $tags = array(); 308 foreach ( $args['post_tags'] as $tag) {327 foreach ($args['post_tags'] as $tag) { 309 328 $tags[] = $tag; 310 329 } … … 312 331 $data['tags_input'] = $tags; 313 332 } else { 314 $default = Quickcreatorblog::get_instance()->get_quickcreator_settings()->get_option( 'content-importer', 'default_tags', false);315 316 if ( false !== $default) {333 $default = Quickcreatorblog::get_instance()->get_quickcreator_settings()->get_option('content-importer', 'default_tags', false); 334 335 if (false !== $default) { 317 336 $data['tags_input'] = $default; 318 337 } … … 327 346 * @return void 328 347 */ 329 private function resolve_post_meta_details( $args, &$data ) { 348 private function resolve_post_meta_details($args, &$data) 349 { 330 350 331 351 $seo_plugin_is_active = false; 332 352 333 if ( ! isset( $data['meta_input'] )) {353 if (! isset($data['meta_input'])) { 334 354 $data['meta_input'] = array(); 335 355 } 336 356 337 if ( isset( $args['meta_input'] )) {338 foreach ( $args['meta_input'] as $key => $value) {339 $data['meta_input'][ $key] = $value;340 } 341 } 342 343 if ( isset( $args['featured_image'] ) && '' !== $args['featured_image']) {344 if ( is_int($args['featured_image'])) {357 if (isset($args['meta_input'])) { 358 foreach ($args['meta_input'] as $key => $value) { 359 $data['meta_input'][$key] = $value; 360 } 361 } 362 363 if (isset($args['featured_image']) && '' !== $args['featured_image']) { 364 if (is_int($args['featured_image'])) { 345 365 $data['meta_input']['_thumbnail_id'] = $args['featured_image']; 346 366 } else { … … 351 371 352 372 // Yoast SEO is active. 353 if ( quickcreator_check_if_plugins_is_active( 'wordpress-seo/wp-seo.php' )) {354 355 if ( isset( $args['meta_title'] ) && '' !== $args['meta_title']) {373 if (quickcreator_check_if_plugins_is_active('wordpress-seo/wp-seo.php')) { 374 375 if (isset($args['meta_title']) && '' !== $args['meta_title']) { 356 376 $data['meta_input']['_yoast_wpseo_title'] = $args['meta_title']; 357 377 } 358 378 359 if ( isset( $args['meta_description'] ) && '' !== $args['meta_description']) {379 if (isset($args['meta_description']) && '' !== $args['meta_description']) { 360 380 $data['meta_input']['_yoast_wpseo_metadesc'] = $args['meta_description']; 361 381 } … … 364 384 } 365 385 366 if ( quickcreator_check_if_plugins_is_active( 'all-in-one-seo-pack/all_in_one_seo_pack.php' ) ) {386 if (quickcreator_check_if_plugins_is_active('all-in-one-seo-pack/all_in_one_seo_pack.php')) { 367 387 $seo_plugin_is_active = true; 368 388 } 369 389 370 390 // Rank Math SEO. 371 if ( quickcreator_check_if_plugins_is_active( 'seo-by-rank-math/rank-math.php' )) {372 373 if ( isset( $args['meta_title'] ) && '' !== $args['meta_title']) {391 if (quickcreator_check_if_plugins_is_active('seo-by-rank-math/rank-math.php')) { 392 393 if (isset($args['meta_title']) && '' !== $args['meta_title']) { 374 394 $data['meta_input']['rank_math_title'] = $args['meta_title']; 375 395 } 376 396 377 if ( isset( $args['meta_description'] ) && '' !== $args['meta_description']) {397 if (isset($args['meta_description']) && '' !== $args['meta_description']) { 378 398 $data['meta_input']['rank_math_description'] = $args['meta_description']; 379 399 } … … 383 403 384 404 // Save in quickcreator Meta to display. 385 if ( ! $seo_plugin_is_active) {386 387 if ( isset( $args['meta_title'] ) && '' !== $args['meta_title']) {405 if (! $seo_plugin_is_active) { 406 407 if (isset($args['meta_title']) && '' !== $args['meta_title']) { 388 408 $data['meta_input']['_quickcreatorblog_title'] = $args['meta_title']; 389 409 } 390 410 391 if ( isset( $args['meta_description'] ) && '' !== $args['meta_description']) {411 if (isset($args['meta_description']) && '' !== $args['meta_description']) { 392 412 $data['meta_input']['_quickcreatorblog_description'] = $args['meta_description']; 393 413 } … … 395 415 } 396 416 397 private function resove_post_meta_after_insert_post( $post_id, $args) { 398 if ( quickcreator_check_if_plugins_is_active( 'all-in-one-seo-pack/all_in_one_seo_pack.php' ) ) { 417 private function resove_post_meta_after_insert_post($post_id, $args) 418 { 419 if (quickcreator_check_if_plugins_is_active('all-in-one-seo-pack/all_in_one_seo_pack.php')) { 399 420 $seo_data = []; 400 if ( isset( $args['meta_title'] ) && '' !== $args['meta_title']) {421 if (isset($args['meta_title']) && '' !== $args['meta_title']) { 401 422 $seo_data['title'] = $args['meta_title']; 402 423 } 403 424 404 if ( isset( $args['meta_description'] ) && '' !== $args['meta_description']) {425 if (isset($args['meta_description']) && '' !== $args['meta_description']) { 405 426 $seo_data['description'] = $args['meta_description']; 406 427 } 407 \AIOSEO\Plugin\Common\Models\Post::savePost( $post_id, $seo_data);428 \AIOSEO\Plugin\Common\Models\Post::savePost($post_id, $seo_data); 408 429 } 409 430 } … … 416 437 * @return int 417 438 */ 418 private function get_user_id_by_login( $login = false ) { 439 private function get_user_id_by_login($login = false) 440 { 419 441 420 442 $user_id = 0; 421 $user = get_user_by( 'login', $login);422 423 if ( false !== $user) {424 $user_id = get_option( 'quickcreator_auth_user', 0);443 $user = get_user_by('login', $login); 444 445 if (false !== $user) { 446 $user_id = get_option('quickcreator_auth_user', 0); 425 447 } 426 448 … … 435 457 * @return bool 436 458 */ 437 public function check_if_plugins_is_active( $plugin ) { 438 439 if ( ! function_exists( 'is_plugin_active' ) ) { 440 return in_array( $plugin, (array) get_option( 'active_plugins', array() ), true ); 441 } else { 442 return is_plugin_active( $plugin ); 459 public function check_if_plugins_is_active($plugin) 460 { 461 462 if (! function_exists('is_plugin_active')) { 463 return in_array($plugin, (array) get_option('active_plugins', array()), true); 464 } else { 465 return is_plugin_active($plugin); 443 466 } 444 467 } -
quickcreator/tags/0.0.7/includes/quickcreator/class-quickcreator.php
r3143504 r3158668 132 132 * @return string 133 133 */ 134 public function get_privacy_policy_url()135 {136 return $this->quickcreator_privacy_policy;137 }134 // public function get_privacy_policy_url() 135 // { 136 // return $this->quickcreator_privacy_policy; 137 // } 138 138 139 139 /** … … 795 795 public function quickcreator_import_post($request) 796 796 { 797 try { 798 $args = array(); 799 $content = $request->get_param('content'); 800 801 if (empty($content) || '' === $content || (is_string($content) && strlen($content) < 1)) { 802 return new WP_REST_Response( 803 array( 804 'error' => __('Cannot add post with empty content.', 'quickcreator'), 805 ), 806 422 807 ); 808 } 809 810 // $metadata = $request->get_param( 'metadata' ); 811 812 // Optional params. 813 $args['post_id'] = $request->get_param('post_id'); 814 $args['post_title'] = $request->get_param('title') ?? ''; 815 $args['permalink_hash'] = $request->get_param('slug'); 816 $args['post_category'] = $request->get_param('categories') ?? array(); 817 $args['post_tags'] = $request->get_param('tags') ?? array(); 818 $args['post_author'] = $request->get_param('author') ?? ''; 819 $args['post_excerpt'] = $request->get_param('excerpt') ?? ''; 820 $args['meta_title'] = $request->get_param('meta_title'); 821 $args['meta_description'] = $request->get_param('meta_description'); 822 $args['post_status'] = $request->get_param('status'); 823 $args['post_type'] = $request->get_param('post_type') ?? ''; 824 $args["meta_input"] = $request->get_param('meta') ?? array(); 825 $args['post_parent'] = $request->get_param('post_parent') ?? 0; 826 $args['filter'] = $request->get_param('filter') ?? ''; 827 $featured_image = $request->get_param('featured_image'); 828 if ($featured_image !== null && $featured_image !== '') { 829 $args['featured_image'] = $featured_image; # quickcreator_sync_image_to_media_library($request->get_param( 'featured_image' )); 830 } 831 832 // $args['post_date'] = $metadata['publicationDate'] ?? ''; 833 // $args['tags_input'] = $request->get_param( 'tags_input' ); 834 835 $args['post_name'] = $request->get_param('name'); 836 // $args['draft_id'] = $request->get_param( 'draft_id' ); 837 // $args['keywords'] = $request->get_param( 'keywords' ); 838 // $args['location'] = $request->get_param( 'location' ); 839 840 $modification_date = gmdate('Y-m-d'); 841 if (isset($args['post_id'])) { 842 $modification_date = get_the_modified_time('Y-m-d', $args['post_id']); 843 } 844 845 $post_id = $this->content_importer->save_data_into_database($content, $args); 846 847 if (! is_wp_error($post_id)) { 848 return new WP_REST_Response( 849 array( 850 'post_id' => $post_id, 851 'edit_post_url' => $this->get_edit_post_link($post_id, 'notdisplay'), 852 'post_url' => get_permalink($post_id), 853 'post_status' => get_post_status($post_id), 854 'modified_at' => $modification_date, 855 'url' => site_url(), 856 ) 857 ); 858 } else { 859 return new WP_REST_Response( 860 array( 861 'error' => __('There was an error on post adding', 'quickcreator'), 862 'wp_error_message' => $post_id->get_error_message(), 863 ), 864 403 865 ); 866 } 867 } catch (\Exception $e) { 797 $args = array(); 798 $content = $request->get_param('content'); 799 800 if (empty($content) || '' === $content || (is_string($content) && strlen($content) < 1)) { 801 return new WP_REST_Response( 802 array( 803 'error' => __('Cannot add post with empty content.', 'quickcreator'), 804 ), 805 422 806 ); 807 } 808 809 // $metadata = $request->get_param( 'metadata' ); 810 811 // Optional params. 812 $args['post_id'] = $request->get_param('post_id'); 813 $args['post_title'] = $request->get_param('title') ?? ''; 814 $args['permalink_hash'] = $request->get_param('slug'); 815 $args['post_category'] = $request->get_param('categories') ?? array(); 816 $args['post_tags'] = $request->get_param('tags') ?? array(); 817 $args['post_author'] = $request->get_param('author') ?? ''; 818 $args['post_excerpt'] = $request->get_param('excerpt') ?? ''; 819 $args['meta_title'] = $request->get_param('meta_title'); 820 $args['meta_description'] = $request->get_param('meta_description'); 821 $args['post_status'] = $request->get_param('status'); 822 $args['post_type'] = $request->get_param('post_type') ?? ''; 823 $args["meta_input"] = $request->get_param('meta') ?? array(); 824 $args['post_parent'] = $request->get_param('post_parent') ?? 0; 825 $args['filter'] = $request->get_param('filter') ?? ''; 826 $featured_image = $request->get_param('featured_image'); 827 if ($featured_image !== null && $featured_image !== '') { 828 $args['featured_image'] = $featured_image; # quickcreator_sync_image_to_media_library($request->get_param( 'featured_image' )); 829 } 830 831 // $args['post_date'] = $metadata['publicationDate'] ?? ''; 832 // $args['tags_input'] = $request->get_param( 'tags_input' ); 833 834 $args['post_name'] = $request->get_param('name'); 835 // $args['draft_id'] = $request->get_param( 'draft_id' ); 836 // $args['keywords'] = $request->get_param( 'keywords' ); 837 // $args['location'] = $request->get_param( 'location' ); 838 839 $modification_date = gmdate('Y-m-d'); 840 if (isset($args['post_id'])) { 841 $modification_date = get_the_modified_time('Y-m-d', $args['post_id']); 842 } 843 844 $post_id = $this->content_importer->save_data_into_database($content, $args); 845 846 if (! is_wp_error($post_id)) { 847 return new WP_REST_Response( 848 array( 849 'post_id' => $post_id, 850 'edit_post_url' => $this->get_edit_post_link($post_id, 'notdisplay'), 851 'post_url' => get_permalink($post_id), 852 'post_status' => get_post_status($post_id), 853 'modified_at' => $modification_date, 854 'url' => site_url(), 855 ) 856 ); 857 } else { 868 858 return new WP_REST_Response( 869 859 array( 870 860 'error' => __('There was an error on post adding', 'quickcreator'), 871 'wp_error_message' => $ e->getMessage(),861 'wp_error_message' => $post_id->get_error_message(), 872 862 ), 873 863 403 … … 1392 1382 1393 1383 update_option(ASTRA_THEME_SETTINGS, $options); 1394 wp_update_custom_css_post( '.dynamic-listing .listing {\n\tpadding: 0!important;\n}\n.e-loop-item {\n\tpadding: 0!important;\n}\n.ast-container {\n\tmax-width: 100%;\n\tpadding: 0; \n}\n.qc-square-image img {\n aspect-ratio: 1 / 1!important;\n object-fit: fill!important;\n}');1384 wp_update_custom_css_post(".dynamic-listing .listing {\n\tpadding: 0!important;\n}\n.e-loop-item {\n\tpadding: 0!important;\n}\n.ast-container {\n\tmax-width: 100%;\n\tpadding: 0; \n}\n.qc-square-image img {\n aspect-ratio: 1 / 1!important;\n object-fit: fill!important;\n}"); 1395 1385 } 1396 1386 $page_on_front = $request->get_param('page_on_front'); -
quickcreator/tags/0.0.7/quickcreator.php
r3146823 r3158668 4 4 * Plugin URI: https://wordpress.org/plugins/quickcreator/ 5 5 * Description: Create post with Quickcreator in WordPress 6 * Version: 0.0. 66 * Version: 0.0.7 7 7 * Author: Quickcreator 8 8 * Author URI: https://quickcreator.io -
quickcreator/tags/0.0.7/readme.txt
r3146823 r3158668 5 5 Requires PHP: 7.4 6 6 Tested up to: 6.6 7 Stable tag: 0.0. 67 Stable tag: 0.0.7 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html -
quickcreator/trunk/includes/quickcreator/class-content-importer.php
r3142565 r3158668 1 1 <?php 2 2 3 /** 3 4 * Object that handle importing content from: … … 18 19 * Object that imports data from different sources into WordPress. 19 20 */ 20 class Content_Importer { 21 class Content_Importer 22 { 21 23 22 24 /** … … 31 33 * Basic construct. 32 34 */ 33 public function __construct() { 35 public function __construct() 36 { 34 37 $this->content_parser = new Parsers_Controller(); 35 38 } … … 43 46 * @return int|WP_Error 44 47 */ 45 public function save_data_into_database( $content, $args = array()) { 48 public function save_data_into_database($content, $args = array()) 49 { 46 50 $user = get_users()[0]; 47 wp_set_current_user( $user->ID, $user->data->display_name);48 if ( 'elementor' === $args['filter']) {51 wp_set_current_user($user->ID, $user->data->display_name); 52 if ('elementor' === $args['filter']) { 49 53 $if_elementor_is_active = quickcreator_check_if_plugins_is_active('elementor/elementor.php'); 50 54 if ($if_elementor_is_active) { 51 55 $rawContent = ""; 52 56 } 53 } else if ( 'raw' !== $args['filter']) {54 $rawContent = $this->content_parser->parse_content( $content);57 } else if ('raw' !== $args['filter']) { 58 $rawContent = $this->content_parser->parse_content($content); 55 59 } else { 56 60 $this->content_parser->choose_parser(); 57 61 $rawContent = $content; 58 62 } 59 $title = isset( $args['post_title'] ) && strlen( $args['post_title']) > 0 ? $args['post_title'] : $this->content_parser->return_title();63 $title = isset($args['post_title']) && strlen($args['post_title']) > 0 ? $args['post_title'] : $this->content_parser->return_title(); 60 64 61 65 $data = array( … … 64 68 ); 65 69 66 if ( isset( $args['post_id'] ) && $args['post_id'] > 0) {70 if (isset($args['post_id']) && $args['post_id'] > 0) { 67 71 68 72 $provided_post_id = $args['post_id']; … … 75 79 } 76 80 77 $this->resolve_post_author( $args, $data);78 $this->resolve_post_status( $args, $data);79 $this->resolve_post_type( $args, $data);80 $this->resolve_post_permalink( $args, $data);81 $this->resolve_post_category( $args, $data);82 $this->resolve_post_tags( $args, $data);83 $this->resolve_post_meta_details( $args, $data);84 $this->resolve_post_excerpt( $args, $data);85 $this->resolve_post_parent( $args, $data);86 87 if ( isset( $post ) && 'published' === $post['post_status']) {81 $this->resolve_post_author($args, $data); 82 $this->resolve_post_status($args, $data); 83 $this->resolve_post_type($args, $data); 84 $this->resolve_post_permalink($args, $data); 85 $this->resolve_post_category($args, $data); 86 $this->resolve_post_tags($args, $data); 87 $this->resolve_post_meta_details($args, $data); 88 $this->resolve_post_excerpt($args, $data); 89 $this->resolve_post_parent($args, $data); 90 91 if (isset($post) && 'published' === $post['post_status']) { 88 92 // WordPress set current date as default and we do not want to change publication date. 89 93 $data['post_date'] = $post['post_date']; 90 94 } else { 91 $this->resolve_post_date( $args, $data);92 } 93 94 $post_id = wp_insert_post( $data, true);95 96 if ( ! is_wp_error( $post_id ) && isset( $args['draft_id'] )) {97 update_post_meta( $post_id, 'quickcreator_draft_id', $args['draft_id']);98 update_post_meta( $post_id, 'quickcreator_permalink_hash', isset( $args['permalink_hash'] ) ? $args['permalink_hash'] : '');99 update_post_meta( $post_id, 'quickcreator_keywords', $args['keywords']);100 update_post_meta( $post_id, 'quickcreator_location', $args['location']);101 update_post_meta( $post_id, 'quickcreator_scrape_ready', true);102 update_post_meta( $post_id, 'quickcreator_last_post_update', round( microtime( true ) * 1000 ));103 update_post_meta( $post_id, 'quickcreator_last_post_update_direction', 'from Quickcreator to WordPress');104 } 105 106 $this->resove_post_meta_after_insert_post( $post_id, $args);107 108 if ( 'elementor' === $args['filter']) {95 $this->resolve_post_date($args, $data); 96 } 97 98 $post_id = wp_insert_post($data, true); 99 100 if (! is_wp_error($post_id) && isset($args['draft_id'])) { 101 update_post_meta($post_id, 'quickcreator_draft_id', $args['draft_id']); 102 update_post_meta($post_id, 'quickcreator_permalink_hash', isset($args['permalink_hash']) ? $args['permalink_hash'] : ''); 103 update_post_meta($post_id, 'quickcreator_keywords', $args['keywords']); 104 update_post_meta($post_id, 'quickcreator_location', $args['location']); 105 update_post_meta($post_id, 'quickcreator_scrape_ready', true); 106 update_post_meta($post_id, 'quickcreator_last_post_update', round(microtime(true) * 1000)); 107 update_post_meta($post_id, 'quickcreator_last_post_update_direction', 'from Quickcreator to WordPress'); 108 } 109 110 $this->resove_post_meta_after_insert_post($post_id, $args); 111 112 if ('elementor' === $args['filter']) { 109 113 $if_elementor_is_active = quickcreator_check_if_plugins_is_active('elementor/elementor.php'); 110 114 if ($if_elementor_is_active) { 111 \Elementor\Plugin::$instance->documents->ajax_save( [ 112 'editor_post_id' => $post_id, 113 'status' => $data["post_status"], 114 'elements' => $content['elements'], 115 'settings' => $content['settings'], 116 ] ); 117 } 118 } else { 119 $this->content_parser->run_after_post_insert_actions( $post_id ); 115 \Elementor\Plugin::$instance->documents->ajax_save([ 116 'editor_post_id' => $post_id, 117 'status' => $data["post_status"], 118 'elements' => $content['elements'], 119 'settings' => $content['settings'], 120 ]); 121 if (isset($args['meta_input']) && isset($args['meta_input']['_elementor_template_type']) && "kit" === $args['meta_input']['_elementor_template_type']) { 122 $kits_manager = \Elementor\Plugin::$instance->kits_manager; 123 update_option($kits_manager::OPTION_PREVIOUS, $kits_manager->get_active_id()); 124 update_option($kits_manager::OPTION_ACTIVE, $post_id); 125 } 126 } 127 } else { 128 $this->content_parser->run_after_post_insert_actions($post_id); 120 129 } 121 130 return $post_id; … … 129 138 * @return array URL to image in media library. 130 139 */ 131 public function upload_img_to_media_library( $image_url, $image_alt ) { 132 $image_data = $this->content_parser->upload_img_to_media_library( $image_url, $image_alt); 140 public function upload_img_to_media_library($image_url, $image_alt) 141 { 142 $image_data = $this->content_parser->upload_img_to_media_library($image_url, $image_alt); 133 143 $image_url = $image_data['url']; 134 144 $image_id = $image_data['id']; … … 152 162 * @return void 153 163 */ 154 private function resolve_post_author( $args, &$data ) { 155 156 if ( isset( $args['post_author'] ) && '' !== $args['post_author'] ) { 164 private function resolve_post_author($args, &$data) 165 { 166 167 if (isset($args['post_author']) && '' !== $args['post_author']) { 157 168 158 169 $value = $args['post_author']; 159 170 160 if ( is_numeric( $value ) && $value > 0) {171 if (is_numeric($value) && $value > 0) { 161 172 $data['post_author'] = $value; 162 173 } else { 163 $data['post_author'] = $this->get_user_id_by_login( $value);164 } 165 } else { 166 $default = Quickcreator()->get_quickcreator_settings()->get_option( 'content-importer', 'default_post_author', false);167 168 if ( false !== $default) {174 $data['post_author'] = $this->get_user_id_by_login($value); 175 } 176 } else { 177 $default = Quickcreator()->get_quickcreator_settings()->get_option('content-importer', 'default_post_author', false); 178 179 if (false !== $default) { 169 180 $data['post_author'] = $default; 170 181 } 171 182 } 172 183 } 173 184 174 185 /** 175 186 * Fill $data array with proper attribute for post_excerpt or leave empty to fill default. … … 179 190 * @return void 180 191 */ 181 private function resolve_post_excerpt( $args, &$data) { 182 if ( isset( $args['post_excerpt'] ) && '' !== $args['post_excerpt'] ) { 192 private function resolve_post_excerpt($args, &$data) 193 { 194 if (isset($args['post_excerpt']) && '' !== $args['post_excerpt']) { 183 195 $data['post_excerpt'] = $args['post_excerpt']; 184 } 196 } 185 197 } 186 198 … … 192 204 * @return void 193 205 */ 194 private function resolve_post_status( $args, &$data ) { 195 196 $allowed_statuses = array( 'publish', 'draft', 'pending', 'future', 'private' ); 197 198 if ( isset( $args['post_status'] ) && '' !== $args['post_status'] && in_array( $args['post_status'], $allowed_statuses, true ) ) { 206 private function resolve_post_status($args, &$data) 207 { 208 209 $allowed_statuses = array('publish', 'draft', 'pending', 'future', 'private'); 210 211 if (isset($args['post_status']) && '' !== $args['post_status'] && in_array($args['post_status'], $allowed_statuses, true)) { 199 212 $data['post_status'] = $args['post_status']; 200 213 } else { 201 $default = Quickcreatorblog::get_instance()->get_quickcreator_settings()->get_option( 'content-importer', 'default_post_status', false);202 203 if ( false !== $default) {214 $default = Quickcreatorblog::get_instance()->get_quickcreator_settings()->get_option('content-importer', 'default_post_status', false); 215 216 if (false !== $default) { 204 217 $data['post_status'] = $default; 205 218 } … … 214 227 * @return void 215 228 */ 216 private function resolve_post_type( $args, &$data ) { 229 private function resolve_post_type($args, &$data) 230 { 217 231 218 232 $allowed_post_types = quickcreator_return_supported_post_types(); 219 233 220 if ( isset( $args['post_type'] ) && '' !== $args['post_type'] && in_array( $args['post_type'], $allowed_post_types, true )) {234 if (isset($args['post_type']) && '' !== $args['post_type'] && in_array($args['post_type'], $allowed_post_types, true)) { 221 235 $data['post_type'] = $args['post_type']; 222 236 } else { … … 232 246 * @return void 233 247 */ 234 private function resolve_post_date( $args, &$data ) { 235 236 if ( isset( $args['post_date'] ) && strtotime( $args['post_date'] ) > time() ) { 237 $data['post_date'] = gmdate( 'Y-m-d H:i:s', strtotime( $args['post_date'] ) ); 248 private function resolve_post_date($args, &$data) 249 { 250 251 if (isset($args['post_date']) && strtotime($args['post_date']) > time()) { 252 $data['post_date'] = gmdate('Y-m-d H:i:s', strtotime($args['post_date'])); 238 253 } 239 254 } … … 246 261 * @return void 247 262 */ 248 private function resolve_post_parent($args, &$data) { 249 250 if ( isset( $args['post_parent'] ) && '' !== $args['post_parent'] ) { 263 private function resolve_post_parent($args, &$data) 264 { 265 266 if (isset($args['post_parent']) && '' !== $args['post_parent']) { 251 267 $data['post_parent'] = $args['post_parent']; 252 268 } … … 261 277 * @return void 262 278 */ 263 private function resolve_post_permalink( $args, &$data ) { 264 265 if ( isset( $args['post_name'] ) && '' !== $args['post_name'] ) { 279 private function resolve_post_permalink($args, &$data) 280 { 281 282 if (isset($args['post_name']) && '' !== $args['post_name']) { 266 283 $data['post_name'] = $args['post_name']; 267 284 } … … 275 292 * @return void 276 293 */ 277 private function resolve_post_category( $args, &$data ) { 278 279 if ( isset( $args['post_category'] ) && is_array( $args['post_category'] ) && ! empty( $args['post_category'] ) ) { 294 private function resolve_post_category($args, &$data) 295 { 296 297 if (isset($args['post_category']) && is_array($args['post_category']) && ! empty($args['post_category'])) { 280 298 281 299 $categories = array(); 282 foreach ( $args['post_category'] as $category) {300 foreach ($args['post_category'] as $category) { 283 301 $categories[] = $category; 284 302 } … … 286 304 $data['post_category'] = $categories; 287 305 } else { 288 $default = Quickcreatorblog::get_instance()->get_quickcreator_settings()->get_option( 'content-importer', 'default_category', false);289 290 if ( false !== $default) {291 $data['post_category'] = array( $default);306 $default = Quickcreatorblog::get_instance()->get_quickcreator_settings()->get_option('content-importer', 'default_category', false); 307 308 if (false !== $default) { 309 $data['post_category'] = array($default); 292 310 } 293 311 } … … 301 319 * @return void 302 320 */ 303 private function resolve_post_tags( $args, &$data ) { 304 305 if ( isset( $args['post_tags'] ) && is_array( $args['post_tags'] ) && count( $args['post_tags'] ) > 0 ) { 321 private function resolve_post_tags($args, &$data) 322 { 323 324 if (isset($args['post_tags']) && is_array($args['post_tags']) && count($args['post_tags']) > 0) { 306 325 307 326 $tags = array(); 308 foreach ( $args['post_tags'] as $tag) {327 foreach ($args['post_tags'] as $tag) { 309 328 $tags[] = $tag; 310 329 } … … 312 331 $data['tags_input'] = $tags; 313 332 } else { 314 $default = Quickcreatorblog::get_instance()->get_quickcreator_settings()->get_option( 'content-importer', 'default_tags', false);315 316 if ( false !== $default) {333 $default = Quickcreatorblog::get_instance()->get_quickcreator_settings()->get_option('content-importer', 'default_tags', false); 334 335 if (false !== $default) { 317 336 $data['tags_input'] = $default; 318 337 } … … 327 346 * @return void 328 347 */ 329 private function resolve_post_meta_details( $args, &$data ) { 348 private function resolve_post_meta_details($args, &$data) 349 { 330 350 331 351 $seo_plugin_is_active = false; 332 352 333 if ( ! isset( $data['meta_input'] )) {353 if (! isset($data['meta_input'])) { 334 354 $data['meta_input'] = array(); 335 355 } 336 356 337 if ( isset( $args['meta_input'] )) {338 foreach ( $args['meta_input'] as $key => $value) {339 $data['meta_input'][ $key] = $value;340 } 341 } 342 343 if ( isset( $args['featured_image'] ) && '' !== $args['featured_image']) {344 if ( is_int($args['featured_image'])) {357 if (isset($args['meta_input'])) { 358 foreach ($args['meta_input'] as $key => $value) { 359 $data['meta_input'][$key] = $value; 360 } 361 } 362 363 if (isset($args['featured_image']) && '' !== $args['featured_image']) { 364 if (is_int($args['featured_image'])) { 345 365 $data['meta_input']['_thumbnail_id'] = $args['featured_image']; 346 366 } else { … … 351 371 352 372 // Yoast SEO is active. 353 if ( quickcreator_check_if_plugins_is_active( 'wordpress-seo/wp-seo.php' )) {354 355 if ( isset( $args['meta_title'] ) && '' !== $args['meta_title']) {373 if (quickcreator_check_if_plugins_is_active('wordpress-seo/wp-seo.php')) { 374 375 if (isset($args['meta_title']) && '' !== $args['meta_title']) { 356 376 $data['meta_input']['_yoast_wpseo_title'] = $args['meta_title']; 357 377 } 358 378 359 if ( isset( $args['meta_description'] ) && '' !== $args['meta_description']) {379 if (isset($args['meta_description']) && '' !== $args['meta_description']) { 360 380 $data['meta_input']['_yoast_wpseo_metadesc'] = $args['meta_description']; 361 381 } … … 364 384 } 365 385 366 if ( quickcreator_check_if_plugins_is_active( 'all-in-one-seo-pack/all_in_one_seo_pack.php' ) ) {386 if (quickcreator_check_if_plugins_is_active('all-in-one-seo-pack/all_in_one_seo_pack.php')) { 367 387 $seo_plugin_is_active = true; 368 388 } 369 389 370 390 // Rank Math SEO. 371 if ( quickcreator_check_if_plugins_is_active( 'seo-by-rank-math/rank-math.php' )) {372 373 if ( isset( $args['meta_title'] ) && '' !== $args['meta_title']) {391 if (quickcreator_check_if_plugins_is_active('seo-by-rank-math/rank-math.php')) { 392 393 if (isset($args['meta_title']) && '' !== $args['meta_title']) { 374 394 $data['meta_input']['rank_math_title'] = $args['meta_title']; 375 395 } 376 396 377 if ( isset( $args['meta_description'] ) && '' !== $args['meta_description']) {397 if (isset($args['meta_description']) && '' !== $args['meta_description']) { 378 398 $data['meta_input']['rank_math_description'] = $args['meta_description']; 379 399 } … … 383 403 384 404 // Save in quickcreator Meta to display. 385 if ( ! $seo_plugin_is_active) {386 387 if ( isset( $args['meta_title'] ) && '' !== $args['meta_title']) {405 if (! $seo_plugin_is_active) { 406 407 if (isset($args['meta_title']) && '' !== $args['meta_title']) { 388 408 $data['meta_input']['_quickcreatorblog_title'] = $args['meta_title']; 389 409 } 390 410 391 if ( isset( $args['meta_description'] ) && '' !== $args['meta_description']) {411 if (isset($args['meta_description']) && '' !== $args['meta_description']) { 392 412 $data['meta_input']['_quickcreatorblog_description'] = $args['meta_description']; 393 413 } … … 395 415 } 396 416 397 private function resove_post_meta_after_insert_post( $post_id, $args) { 398 if ( quickcreator_check_if_plugins_is_active( 'all-in-one-seo-pack/all_in_one_seo_pack.php' ) ) { 417 private function resove_post_meta_after_insert_post($post_id, $args) 418 { 419 if (quickcreator_check_if_plugins_is_active('all-in-one-seo-pack/all_in_one_seo_pack.php')) { 399 420 $seo_data = []; 400 if ( isset( $args['meta_title'] ) && '' !== $args['meta_title']) {421 if (isset($args['meta_title']) && '' !== $args['meta_title']) { 401 422 $seo_data['title'] = $args['meta_title']; 402 423 } 403 424 404 if ( isset( $args['meta_description'] ) && '' !== $args['meta_description']) {425 if (isset($args['meta_description']) && '' !== $args['meta_description']) { 405 426 $seo_data['description'] = $args['meta_description']; 406 427 } 407 \AIOSEO\Plugin\Common\Models\Post::savePost( $post_id, $seo_data);428 \AIOSEO\Plugin\Common\Models\Post::savePost($post_id, $seo_data); 408 429 } 409 430 } … … 416 437 * @return int 417 438 */ 418 private function get_user_id_by_login( $login = false ) { 439 private function get_user_id_by_login($login = false) 440 { 419 441 420 442 $user_id = 0; 421 $user = get_user_by( 'login', $login);422 423 if ( false !== $user) {424 $user_id = get_option( 'quickcreator_auth_user', 0);443 $user = get_user_by('login', $login); 444 445 if (false !== $user) { 446 $user_id = get_option('quickcreator_auth_user', 0); 425 447 } 426 448 … … 435 457 * @return bool 436 458 */ 437 public function check_if_plugins_is_active( $plugin ) { 438 439 if ( ! function_exists( 'is_plugin_active' ) ) { 440 return in_array( $plugin, (array) get_option( 'active_plugins', array() ), true ); 441 } else { 442 return is_plugin_active( $plugin ); 459 public function check_if_plugins_is_active($plugin) 460 { 461 462 if (! function_exists('is_plugin_active')) { 463 return in_array($plugin, (array) get_option('active_plugins', array()), true); 464 } else { 465 return is_plugin_active($plugin); 443 466 } 444 467 } -
quickcreator/trunk/includes/quickcreator/class-quickcreator.php
r3143504 r3158668 132 132 * @return string 133 133 */ 134 public function get_privacy_policy_url()135 {136 return $this->quickcreator_privacy_policy;137 }134 // public function get_privacy_policy_url() 135 // { 136 // return $this->quickcreator_privacy_policy; 137 // } 138 138 139 139 /** … … 795 795 public function quickcreator_import_post($request) 796 796 { 797 try { 798 $args = array(); 799 $content = $request->get_param('content'); 800 801 if (empty($content) || '' === $content || (is_string($content) && strlen($content) < 1)) { 802 return new WP_REST_Response( 803 array( 804 'error' => __('Cannot add post with empty content.', 'quickcreator'), 805 ), 806 422 807 ); 808 } 809 810 // $metadata = $request->get_param( 'metadata' ); 811 812 // Optional params. 813 $args['post_id'] = $request->get_param('post_id'); 814 $args['post_title'] = $request->get_param('title') ?? ''; 815 $args['permalink_hash'] = $request->get_param('slug'); 816 $args['post_category'] = $request->get_param('categories') ?? array(); 817 $args['post_tags'] = $request->get_param('tags') ?? array(); 818 $args['post_author'] = $request->get_param('author') ?? ''; 819 $args['post_excerpt'] = $request->get_param('excerpt') ?? ''; 820 $args['meta_title'] = $request->get_param('meta_title'); 821 $args['meta_description'] = $request->get_param('meta_description'); 822 $args['post_status'] = $request->get_param('status'); 823 $args['post_type'] = $request->get_param('post_type') ?? ''; 824 $args["meta_input"] = $request->get_param('meta') ?? array(); 825 $args['post_parent'] = $request->get_param('post_parent') ?? 0; 826 $args['filter'] = $request->get_param('filter') ?? ''; 827 $featured_image = $request->get_param('featured_image'); 828 if ($featured_image !== null && $featured_image !== '') { 829 $args['featured_image'] = $featured_image; # quickcreator_sync_image_to_media_library($request->get_param( 'featured_image' )); 830 } 831 832 // $args['post_date'] = $metadata['publicationDate'] ?? ''; 833 // $args['tags_input'] = $request->get_param( 'tags_input' ); 834 835 $args['post_name'] = $request->get_param('name'); 836 // $args['draft_id'] = $request->get_param( 'draft_id' ); 837 // $args['keywords'] = $request->get_param( 'keywords' ); 838 // $args['location'] = $request->get_param( 'location' ); 839 840 $modification_date = gmdate('Y-m-d'); 841 if (isset($args['post_id'])) { 842 $modification_date = get_the_modified_time('Y-m-d', $args['post_id']); 843 } 844 845 $post_id = $this->content_importer->save_data_into_database($content, $args); 846 847 if (! is_wp_error($post_id)) { 848 return new WP_REST_Response( 849 array( 850 'post_id' => $post_id, 851 'edit_post_url' => $this->get_edit_post_link($post_id, 'notdisplay'), 852 'post_url' => get_permalink($post_id), 853 'post_status' => get_post_status($post_id), 854 'modified_at' => $modification_date, 855 'url' => site_url(), 856 ) 857 ); 858 } else { 859 return new WP_REST_Response( 860 array( 861 'error' => __('There was an error on post adding', 'quickcreator'), 862 'wp_error_message' => $post_id->get_error_message(), 863 ), 864 403 865 ); 866 } 867 } catch (\Exception $e) { 797 $args = array(); 798 $content = $request->get_param('content'); 799 800 if (empty($content) || '' === $content || (is_string($content) && strlen($content) < 1)) { 801 return new WP_REST_Response( 802 array( 803 'error' => __('Cannot add post with empty content.', 'quickcreator'), 804 ), 805 422 806 ); 807 } 808 809 // $metadata = $request->get_param( 'metadata' ); 810 811 // Optional params. 812 $args['post_id'] = $request->get_param('post_id'); 813 $args['post_title'] = $request->get_param('title') ?? ''; 814 $args['permalink_hash'] = $request->get_param('slug'); 815 $args['post_category'] = $request->get_param('categories') ?? array(); 816 $args['post_tags'] = $request->get_param('tags') ?? array(); 817 $args['post_author'] = $request->get_param('author') ?? ''; 818 $args['post_excerpt'] = $request->get_param('excerpt') ?? ''; 819 $args['meta_title'] = $request->get_param('meta_title'); 820 $args['meta_description'] = $request->get_param('meta_description'); 821 $args['post_status'] = $request->get_param('status'); 822 $args['post_type'] = $request->get_param('post_type') ?? ''; 823 $args["meta_input"] = $request->get_param('meta') ?? array(); 824 $args['post_parent'] = $request->get_param('post_parent') ?? 0; 825 $args['filter'] = $request->get_param('filter') ?? ''; 826 $featured_image = $request->get_param('featured_image'); 827 if ($featured_image !== null && $featured_image !== '') { 828 $args['featured_image'] = $featured_image; # quickcreator_sync_image_to_media_library($request->get_param( 'featured_image' )); 829 } 830 831 // $args['post_date'] = $metadata['publicationDate'] ?? ''; 832 // $args['tags_input'] = $request->get_param( 'tags_input' ); 833 834 $args['post_name'] = $request->get_param('name'); 835 // $args['draft_id'] = $request->get_param( 'draft_id' ); 836 // $args['keywords'] = $request->get_param( 'keywords' ); 837 // $args['location'] = $request->get_param( 'location' ); 838 839 $modification_date = gmdate('Y-m-d'); 840 if (isset($args['post_id'])) { 841 $modification_date = get_the_modified_time('Y-m-d', $args['post_id']); 842 } 843 844 $post_id = $this->content_importer->save_data_into_database($content, $args); 845 846 if (! is_wp_error($post_id)) { 847 return new WP_REST_Response( 848 array( 849 'post_id' => $post_id, 850 'edit_post_url' => $this->get_edit_post_link($post_id, 'notdisplay'), 851 'post_url' => get_permalink($post_id), 852 'post_status' => get_post_status($post_id), 853 'modified_at' => $modification_date, 854 'url' => site_url(), 855 ) 856 ); 857 } else { 868 858 return new WP_REST_Response( 869 859 array( 870 860 'error' => __('There was an error on post adding', 'quickcreator'), 871 'wp_error_message' => $ e->getMessage(),861 'wp_error_message' => $post_id->get_error_message(), 872 862 ), 873 863 403 … … 1392 1382 1393 1383 update_option(ASTRA_THEME_SETTINGS, $options); 1394 wp_update_custom_css_post( '.dynamic-listing .listing {\n\tpadding: 0!important;\n}\n.e-loop-item {\n\tpadding: 0!important;\n}\n.ast-container {\n\tmax-width: 100%;\n\tpadding: 0; \n}\n.qc-square-image img {\n aspect-ratio: 1 / 1!important;\n object-fit: fill!important;\n}');1384 wp_update_custom_css_post(".dynamic-listing .listing {\n\tpadding: 0!important;\n}\n.e-loop-item {\n\tpadding: 0!important;\n}\n.ast-container {\n\tmax-width: 100%;\n\tpadding: 0; \n}\n.qc-square-image img {\n aspect-ratio: 1 / 1!important;\n object-fit: fill!important;\n}"); 1395 1385 } 1396 1386 $page_on_front = $request->get_param('page_on_front'); -
quickcreator/trunk/quickcreator.php
r3146823 r3158668 4 4 * Plugin URI: https://wordpress.org/plugins/quickcreator/ 5 5 * Description: Create post with Quickcreator in WordPress 6 * Version: 0.0. 66 * Version: 0.0.7 7 7 * Author: Quickcreator 8 8 * Author URI: https://quickcreator.io -
quickcreator/trunk/readme.txt
r3146823 r3158668 5 5 Requires PHP: 7.4 6 6 Tested up to: 6.6 7 Stable tag: 0.0. 67 Stable tag: 0.0.7 8 8 License: GPLv2 or later 9 9 License URI: https://www.gnu.org/licenses/gpl-2.0.html
Note: See TracChangeset
for help on using the changeset viewer.