function g1_simple_slider_add_new_slide() { $ajax_data = $_POST['ajax_data']; $post_parent = get_post($ajax_data['parent_id']); $slide = get_post($ajax_data['attachment_id']); $error_response = $success_response = new WP_Ajax_Response(); $errors = new WP_Error(); if (!$post_parent || !$slide) { $errors->add('incorrect_input_data', 'Slide or parent post does not exist!'); } if (count($errors->get_error_codes()) > 0) { $error_response->add(array('what' => 'errors', 'id' => $errors)); $error_response->send(); exit; } // attach slide to simple_slider wp_update_post(array('ID' => $slide->ID, 'post_parent' => $post_parent->ID)); $slider = G1_Slider_Factory::get_simple_slider($post_parent); $last_slide = $slider->get_last_slide(); $new_slide = new G1_Simple_Slider_Slide($slide); $new_slide->set_order($last_slide->get_order() + 1); $new_slide->save(); $view = new G1_Simple_Slider_Slide_Html_Renderer($new_slide, $slider->get_id()); $success_response->add(array('what' => 'slide_html', 'id' => 1, 'data' => $view->capture())); $success_response->send(); exit; }
/** * Handle Post Customizer AJAX requests * * @access public * @since 0.1.0 */ public function process_ajax_request() { check_ajax_referer('post-customizer'); if (empty($_POST['post_customizer_action'])) { return; } if ('get_sidebar' == $_POST['post_customizer_action']) { if (empty($_POST['post_id'])) { return; } $data = array('sidebarHTML' => $this->_render_sidebar_data($_POST['post_id'])); } elseif ('save_field' == $_POST['post-customizer_action'] && !empty($_POST['field']) && !empty($_POST['post_id'])) { $data = array(); switch ($_POST['field']) { case 'post_title': case 'post_content': wp_update_post(array('ID' => $_POST['post_id'], $_POST['field'] => $_POST['data'])); $data['changed'] = $_POST['field']; $data['value'] = $_POST['data']; break; } } else { //Error! } wp_send_json($data); }
function acfmod_simple_content_save_post($post_id) { // bail early if no ACF data if (empty($_POST['acf'])) { return; } // array of field values $fields = $_POST['acf']; if (!isset($fields['acf_modules_field']) && is_array($fields['acf_modules_field'])) { return; } // This may change in the future... yikes... $delete_content_key = 'field_55686c1d9d812'; // assume we aren't deleting content $do_delete_content = false; // get modules values foreach ($fields['acf_modules_field'] as $module) { if (isset($module[$delete_content_key])) { if ($module[$delete_content_key]) { $do_delete_content = true; } } } // don't store the values for delete and load content fields # not sure how to do that just yet // bail early if we're not deleting the content if (!$do_delete_content) { return; } // clear the post content remove_action('acf/save_post', 'acfmod_simple_content_save_post', 20); $delete_content = array('ID' => $post_id, 'post_content' => ''); wp_update_post($delete_content); add_action('acf/save_post', 'acfmod_simple_content_save_post', 20); }
/** * Generate modular layout data from standard post content. * * @subcommand generate-from-content * @synopsis [--post_type=<post>] [--dry_run] */ public function generate_from_content($args, $assoc_args) { $plugin = Plugin::get_instance(); $builder = $plugin->get_builder('ustwo-page-builder'); $assoc_args = wp_parse_args($assoc_args, array('post_type' => 'post', 'dry_run' => false)); $query_args = array('post_type' => $assoc_args['post_type'], 'post_status' => 'any', 'posts_per_page' => 50); $page = 1; $more_posts = true; while ($more_posts) { $query_args['paged'] = $page; $query = new WP_Query($query_args); foreach ($query->posts as $post) { if (empty($post->post_content)) { continue; } WP_CLI::line("Migrating data for {$post->ID}"); $module = array('name' => 'text', 'attr' => array(array('name' => 'body', 'type' => 'wysiwyg', 'value' => $post->post_content))); $modules = $builder->get_raw_data($post->ID); $modules[] = $module; $modules = $builder->validate_data($modules); if (!$assoc_args['dry_run']) { $modules = $builder->save_data($post->ID, $modules); wp_update_post(array('ID' => $post->ID, 'post_content' => '')); } } $more_posts = $page < absint($query->max_num_pages); $page++; } }
function callback($path = '', $blog_id = 0, $media_id = 0) { $blog_id = $this->api->switch_to_blog_and_validate_user($this->api->get_blog_id($blog_id)); if (is_wp_error($blog_id)) { return $blog_id; } if (!current_user_can('upload_files', $media_id)) { return new WP_Error('unauthorized', 'User cannot view media', 403); } $item = $this->get_media_item($media_id); if (is_wp_error($item)) { return new WP_Error('unknown_media', 'Unknown Media', 404); } $input = $this->input(true); $insert = array(); if (!empty($input['title'])) { $insert['post_title'] = $input['title']; } if (!empty($input['caption'])) { $insert['post_excerpt'] = $input['caption']; } if (!empty($input['description'])) { $insert['post_content'] = $input['description']; } $insert['ID'] = $media_id; wp_update_post((object) $insert); $item = $this->get_media_item($media_id); return $item; }
/** * Create a WP post and "sync" it to Elasticsearch. We are mocking the sync * * @param array $post_args * @param array $post_meta * @param int $site_id * @since 0.9 * @return int|WP_Error */ function ep_create_and_sync_post($post_args = array(), $post_meta = array(), $site_id = null) { if ($site_id != null) { switch_to_blog($site_id); } $post_types = ep_get_indexable_post_types(); $post_type_values = array_values($post_types); $args = array('post_status' => 'publish', 'post_title' => 'Test Post ' . time()); if (!empty($post_type_values)) { $args['post_type'] = $post_type_values[0]; } $args = wp_parse_args($post_args, $args); $post_id = wp_insert_post($args); // Quit if we have a WP_Error object if (is_wp_error($post_id)) { return $post_id; } if (!empty($post_meta)) { foreach ($post_meta as $key => $value) { // No need for sanitization here update_post_meta($post_id, $key, $value); } } // Force a re-sync wp_update_post(array('ID' => $post_id)); if ($site_id != null) { restore_current_blog(); } return $post_id; }
public function githubHook($route) { $github = new Github(); $http = herbert('http'); $fd = get_option('gitcontent_settings'); if ($route != $fd['route']) { return; } $args = ['meta_query' => [['key' => '_gitcontent_file', 'value' => '', 'compare' => '!=']]]; $posts = get_posts($args); foreach ($posts as $post) { $file = get_post_meta($post->ID, '_gitcontent_file', true); $inputs = get_option('gitcontent_settings'); $response = $github->checkFile($inputs, $file); $markdownFile = Helper::storagePath($post->ID); if ($response === false) { return; } if ($github->downloadFile($inputs, $response, $markdownFile) === false) { return; } wp_update_post(['ID' => $post->ID, 'post_content' => (new ParsedownExtra())->text(file_get_contents($markdownFile))], false); } echo 'Done'; }
function tdomf_auto_fix_authors() { global $wpdb; if (get_option(TDOMF_AUTO_FIX_AUTHOR)) { // grab posts $query = "SELECT ID, post_author, meta_value "; $query .= "FROM {$wpdb->posts} "; $query .= "LEFT JOIN {$wpdb->postmeta} ON ({$wpdb->posts}.ID = {$wpdb->postmeta}.post_id) "; $query .= "WHERE meta_key = '" . TDOMF_KEY_USER_ID . "' "; $query .= "AND meta_value != post_author "; $query .= "ORDER BY ID DESC"; $posts = $wpdb->get_results($query); if (!empty($posts)) { $count = 0; foreach ($posts as $post) { if ($post->meta_value != $post->post_author && !empty($post->meta_value) && $post->meta_value > 0) { $count++; tdomf_log_message("Changing author (currently {$post->post_author}) on post {$post->ID} to submitter setting {$post->meta_value}."); echo $post->ID . ", "; $postargs = array("ID" => $post->ID, "post_author" => $post->meta_value); wp_update_post($postargs); } } return $count; } else { return 0; } } return false; }
/** * Send an alert */ public function job_manager_alert($alert_id, $force = false) { $alert = get_post($alert_id); if (!$alert || $alert->post_type !== 'job_alert') { return; } if ($alert->post_status !== 'publish' && !$force) { return; } $user = get_user_by('id', $alert->post_author); $jobs = $this->get_matching_jobs($alert, $force); if ($jobs->found_posts || !get_option('job_manager_alerts_matches_only')) { $email = $this->format_email($alert, $user, $jobs); add_filter('wp_mail_from_name', array($this, 'mail_from_name')); add_filter('wp_mail_from', array($this, 'mail_from_email')); if ($email) { wp_mail($user->user_email, apply_filters('job_manager_alerts_subject', sprintf(__('Job Alert Results Matching "%s"', 'wp-job-manager-alerts'), $alert->post_title), $alert), $email); } remove_filter('wp_mail_from_name', array($this, 'mail_from_name')); remove_filter('wp_mail_from', array($this, 'mail_from_email')); } if (($days_to_disable = get_option('job_manager_alerts_auto_disable')) > 0) { $days = (strtotime('NOW') - strtotime($alert->post_modified)) / (60 * 60 * 24); if ($days > $days_to_disable) { $update_alert = array(); $update_alert['ID'] = $alert->ID; $update_alert['post_status'] = 'draft'; wp_update_post($update_alert); wp_clear_scheduled_hook('job-manager-alert', array($alert->ID)); return; } } // Inc sent count update_post_meta($alert->ID, 'send_count', 1 + absint(get_post_meta($alert->ID, 'send_count', true))); }
function piskotki_create_page() { global $wpdb; $page_title = 'Piškotki'; $page_name = 'piskotki'; delete_option('piskotki_page_title'); add_option('piskotki_page_title', $page_title, '', 'yes'); delete_option('piskotki_page_name'); add_option('piskotki_page_name', $page_name, '', 'yes'); delete_option('piskotki_page_id'); add_option('piskotki_page_id', '0', '', 'yes'); $page = get_page_by_title($page_title); if (!$page) { $_p = array(); $_p['post_title'] = $page_title; $_p['post_content'] = "To besedilo se lahko prepiše preko vtičnika. Ne urejajte ga tukaj!"; $_p['post_status'] = 'publish'; $_p['post_type'] = 'page'; $_p['comment_status'] = 'closed'; $_p['ping_status'] = 'closed'; $page_id = wp_insert_post($_p); } else { $page_id = $page->ID; $page->post_status = 'publish'; $page_id = wp_update_post($page); delete_option('piskotki_page_id'); add_option('piskotki_page_id', $page_id); } }
/** * @return int|bool Integer on success, false on failure. */ public function save() { $args = array('post_type' => $this->post_type, 'post_status' => 'publish'); if ($this->c->exists()) { $args['ID'] = $this->c->get_id(); } // WP will gobble up LaTeX escape characters. $content = $this->c->get_content(); $content = $this->pf->convert_delims($content); $content = $this->pf->swap_latex_escape_characters($content); $args['post_content'] = $content; $args['post_author'] = $this->c->get_author_id(); if (null !== $this->c->get_post_date()) { // todo gmt $args['post_date'] = $this->c->get_post_date(); } if ($this->c->exists()) { $saved = wp_update_post($args); } else { $saved = wp_insert_post($args); if ($saved && !is_wp_error($saved)) { $this->c->set_id($saved); } } return $saved; }
/** * Run the converter now * * @since 1.0 * * @param array $args can be extension * @param array $vars */ function update_attachments($args = array(), $vars = array()) { $images = Tiff_Converter::get_images(); $mime_type = 'image/jpg'; // Maybe $args[0] for changing it if ($images) { $succeed = $failed = 0; foreach ($images as $image) { $file = get_attached_file($image->ID); $result = Tiff_Converter_Handle::convert_image($file, $mime_type); if (!is_wp_error($result)) { $update_args = array('ID' => $image->ID, 'post_mime_type' => $result['mime-type']); $result2 = wp_update_post($update_args, true); if ($result2 && !is_wp_error($result2)) { unlink($file); update_attached_file($image->ID, $result['path']); wp_update_attachment_metadata($image->ID, wp_generate_attachment_metadata($image->ID, $result['path'])); $succeed++; } else { unlink($result['path']); $failed++; } } else { $failed++; } } WP_CLI::success(sprintf('%d images are converted and %s failed', $succeed, $failed)); } else { WP_CLI::success('No images to convert'); } }
public function __construct() { global $WCMp; if (get_option("dc_product_vendor_plugin_page_install") == 1) { $wcmp_pages = get_option('wcmp_pages_settings_name'); if (isset($wcmp_pages['vendor_dashboard'])) { wp_update_post(array('ID' => $wcmp_pages['vendor_dashboard'], 'post_content' => '[vendor_dashboard]')); } if (isset($wcmp_pages['vendor_messages'])) { wp_update_post(array('ID' => $wcmp_pages['vendor_messages'], 'post_content' => '[vendor_announcements]', 'post_name' => 'vendor_announcements', 'post_title' => 'Vendor Announcements')); $page_id = $wcmp_pages['vendor_messages']; unset($wcmp_pages['vendor_messages']); $wcmp_pages['vendor_announcements'] = $page_id; update_option('wcmp_pages_settings_name', $wcmp_pages); } } if (!get_option("dc_product_vendor_plugin_page_install")) { $this->wcmp_product_vendor_plugin_create_pages(); } update_option("dc_product_vendor_plugin_db_version", $WCMp->version); update_option("dc_product_vendor_plugin_page_install", 1); $this->save_default_plugin_settings(); $this->wcmp_plugin_tables_install(); $this->remove_other_vendors_plugin_role(); }
/** * @param array $property */ public function posts(array $property) { //get post data $property_formatted = array(); //reassign fields to ones that look good $property_formatted['price'] = $property['Lp_dol']; $property_formatted['mls'] = $property['Ml_num']; $property_formatted['address'] = $property['Addr']; $property_formatted['bathrooms'] = $property['Bath_tot']; $property_formatted['bedrooms'] = $property['Br']; $property_formatted['province'] = $property['County']; $property_formatted['broker'] = $property['Rltr']; $property_formatted['rooms'] = $property['Rms']; $property_formatted['rentorsale'] = $property['S_r']; $property_formatted['status'] = $property['Status']; $property_formatted['postal_code'] = $property['Zip']; $property_formatted['city'] = $property['Area']; $property_formatted['last_updated_text'] = $property['Timestamp_sql']; $property_formatted['last_updated_photos'] = $property['Pix_updt']; $property_formatted['description'] = $property['Ad_text']; $property_formatted['full_dump'] = $property; //set up arguments before entering post to wp $post_args = array('post_content' => $property_formatted['description'], 'ID' => $this->id, 'post_type' => 'property'); //insert post and return new post id $posted = wp_update_post($post_args, true); //add post meta using the new post id and good looking array foreach ($property_formatted as $key => $value) { if (!empty($value)) { add_post_meta($this->id, 'wptrebs_' . $key, $value, true) || update_post_meta($this->id, 'wptrebs_' . $key, $value); } } }
/** * Setup the tests object. */ public function setUp() { parent::setUp(); $this->basicSetUp(); // Lesson with more tag only. $lesson1 = get_post($this->lessons[0]); $lesson1->post_excerpt = ''; $lesson1->post_content = <<<EOT This text can be visible to anyone.<!--more--> This text must be visible to the students who registered for this course. EOT; wp_update_post($lesson1); // Lesson without more tag and excerpt. $lesson2 = get_post($this->lessons[1]); $lesson2->post_excerpt = ''; $lesson2->post_content = <<<EOT This text must be visible to the students who registered for this course. EOT; wp_update_post($lesson2); // Lesson with excerpt only. $this->lesson3 = $this->addLesson(array('course_id' => $this->courses[0], 'author_id' => $this->users['lecturer1'], 'slug' => 'course-1-lesson-3', 'title' => 'course 1 lesson 3')); $lesson3 = get_post($this->lesson3); $lesson3->post_excerpt = 'This excerpt is visible to everyone.'; $lesson3->post_content = <<<EOT This text must be visible to the students who registered for this course. EOT; wp_update_post($lesson3); $this->open_lesson = $this->addLesson(array('course_id' => $this->courses[0], 'author_id' => $this->users['lecturer1'], 'slug' => 'course-1-open-lesson', 'title' => 'course 1 open lesson')); $open_lesson = get_post($this->open_lesson); $open_lesson->post_excerpt = 'Post excerpt.'; $open_lesson->post_content = 'Hidden content.'; wp_update_post($open_lesson); }
/** * @return int|WP_Error */ private function perform_update() { //build the insert args $args = array('post_type' => $this->table); //combine the default with $args $args = array_merge($args, $this->defaults); foreach ($this->mapped as $key => $val) { $args[$val] = $this->{$key}; } //insert post $id = wp_update_post($args); if ($id) { //parse the relations foreach ($this->relations as $relation) { $prop = $relation['map']; if ($relation['type'] == 'meta') { update_post_meta($id, $relation['key'], $this->{$prop}); } elseif ($relation['type'] == 'taxonomy') { /** * This process will assign this post to taxonomy, if taxonomy not exist, create it * The property should be array of name,slug or id */ $taxs = array(); //the input should be array of string or id if (!is_array($this->{$prop})) { $this->{$prop} = array_filter(explode(',', $this->{$prop})); } $t = null; foreach ($this->{$prop} as $tax) { if (filter_var($tax, FILTER_VALIDATE_INT)) { //include to the tax array $term = get_term($tax, $relation['key']); if (is_object($term)) { $taxs[] = $term->name; } else { var_dump($term); } } else { $taxs[] = $tax; } } //now we got the ids, assign post to this tax wp_set_object_terms($id, $taxs, $relation['key']); } elseif ($relation['type'] == 'meta_array') { $data = array(); $format = explode('|', $relation['array_key']); $fields = explode('|', $relation['map']); $map = array_combine($format, $fields); foreach ($map as $key => $val) { $data[$key] = $this->{$val}; } if ($relation['format'] == 'json') { json_encode($data); } update_post_meta($this->id, $relation['key'], $data); } } return $id; } }
/** * Generates the URL to redirect to * @param $location The redirect location (we're overwriting this) * @return string The new URL to redirect to, which should be the post listing page of the relevant post type */ public static function redirect($location) { if (!isset($_POST['save-visit'])) { return $location; } // determine the post status (private if selected, else published) //$post_status = ($_POST['post_status'] == 'private') ? 'private' : 'publish'; // we want to publish new posts $post_status = 'publish'; // if the post was published, allow the status to be changed to something else (eg. draft) if ($_POST['original_post_status'] == 'publish' || $_POST['original_post_status'] == 'private') { $post_status = $_POST['post_status']; } // handle private post visibility if ($_POST['post_status'] == 'private') { $post_status = 'private'; } wp_update_post(array('ID' => $_POST['post_ID'], 'post_status' => $post_status)); // if we have an HTTP referer saved, and it's a post listing page, redirect back to that (maintains pagination, filters, etc.) if (isset($_POST['savevisit_referer']) && strstr($_POST['savevisit_referer'], 'edit.php') !== false) { if (strstr($_POST['savevisit_referer'], 'lbsmessage') === false) { if (strstr($_POST['savevisit_referer'], '?') === false) { return $_POST['savevisit_referer'] . '?lbsmessage=1'; } return $_POST['savevisit_referer'] . '&lbsmessage=1'; } return $_POST['savevisit_referer']; } else { //return get_admin_url() . 'edit.php?lbsmessage=1&post_type=' . $_POST['post_type']; return get_permalink($_POST['post_ID']); } }
function actualizar_contenido($id_post = false, $txt = false) { if (!$id_post || !$txt) { return; } return wp_update_post(array('post_content' => $txt, 'ID' => $id_post)); }
static function import_post($post_data, $type = 'post', $status = null) { //Wordpress::log($post_data); $core['post_type'] = $type; if ($status) { $core['post_status'] = $status; } $core_fields = static::core_fields(); foreach ($core_fields as $core_field) { if (isset($post_data[$core_field])) { $core[$core_field] = $post_data[$core_field]; unset($post_data[$core_field]); } } if (!isset($core['ID']) && isset($core['post_name']) && isset($core['post_type'])) { global $wpdb; $ID = $wpdb->get_var($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_name = %s AND post_type = %s", $core['post_name'], $core['post_type'])); if (is_wp_error($ID)) { throw new \Exception($ID); } $core['ID'] = $ID; } $ID = empty($core['ID']) ? wp_insert_post($core, true) : wp_update_post($core, true); if (is_wp_error($ID)) { throw new \Exception($ID->get_error_message()); } foreach ($post_data as $key => $value) { update_post_meta($ID, $key, $value); } return $ID; }
function activity_admin_post_category_check($post_id, $post, $update) { if (is_admin()) { if (is_plugin_active('activity/activity.php')) { $post_cat = wp_get_post_categories($post_id); if (empty($post_cat)) { return; } else { $activity_cat = intval(get_option('activity_category')); $is_post_activity = in_array($activity_cat, $post_cat); if ($is_post_activity) { if (strpos($_SERVER['REQUEST_URI'], '/wp-admin/admin.php?page=activity_admin') === false) { $post_cat = array_diff($post_cat, array($activity_cat)); if (empty($post_cat)) { $post_cat = array(1); } $post_data = array('ID' => $post_id, 'post_category' => $post_cat); $post_update = wp_update_post($post_data); header('Location: ' . get_site_url() . '/wp-admin/admin.php?page=activity_admin&action=error_add_activity'); exit; } } } } } }
public static function save_name($post_id) { // Refuse without valid nonce: if (!isset($_POST['scholar_name_nonce']) || !wp_verify_nonce($_POST['scholar_name_nonce'], plugin_basename(__FILE__))) { return; } //sanitize user input $prefix = sanitize_text_field($_POST['scholar_name_prefix']); $first = sanitize_text_field($_POST['scholar_name_first']); $middle = sanitize_text_field($_POST['scholar_name_middle']); $last = sanitize_text_field($_POST['scholar_name_last']); $gender = sanitize_text_field($_POST['scholar_name_gender']); $suffix = sanitize_text_field($_POST['scholar_name_suffix']); // Save the data: add_post_meta($post_id, 'scholar_prefix', $prefix, true) or update_post_meta($post_id, 'scholar_prefix', $prefix); add_post_meta($post_id, 'scholar_first_name', $first, true) or update_post_meta($post_id, 'scholar_first_name', $first); add_post_meta($post_id, 'scholar_last_name', $last, true) or update_post_meta($post_id, 'scholar_last_name', $last); add_post_meta($post_id, 'scholar_middle_name', $middle, true) or update_post_meta($post_id, 'scholar_middle_name', $middle); add_post_meta($post_id, 'scholar_gender', $gender, true) or update_post_meta($post_id, 'scholar_gender', $gender); add_post_meta($post_id, 'scholar_suffix', $suffix, true) or update_post_meta($post_id, 'scholar_suffix', $suffix); // Update the post slug: // unhook this function to prevent infinite looping remove_action('save_post', 'ScholarPerson::save_name'); $post_name = implode(' ', compact('prefix', 'first', 'middle', 'last')); if (!empty($suffix)) { $post_name .= ', ' . $suffix; } // update the post slug wp_update_post(array('ID' => $post_id, 'post_name' => sanitize_title($post_name))); // re-hook this function add_action('save_post', 'ScholarPerson::save_name'); }
/** * function wpminv_save_invoice_on_save() * * Saves the title of the invoice on post save * * @param (int) $post_id is the id of the current post being saved */ function wpminv_save_invoice_on_save($post_id) { /* if we have a client id posted */ if (isset($_POST['_wpminv_client']['cmb-field-0'])) { /* get a company name */ $client_post_id = sanitize_text_field($_POST['_wpminv_client']['cmb-field-0']); /* if we have a client post id */ if ($client_post_id != '') { /* get the clients company name */ $title = get_post_meta($client_post_id, '_wpminv_company_name', true); /* if client has no company name */ if ($title == '') { /* set title to company name */ $title = get_post_meta($client_post_id, '_wpminv_first_name', true) . ' ' . get_post_meta($client_post_id, '_wpminv_last_name', true); } /* no client added to invoice */ } else { $title = 'No client selected'; } /* unhook this function so it doesn't loop infinitely */ remove_action('save_post_wpminv_invoice', 'wpminv_save_invoice_on_save', 99, 1); /* update the post title to store the first and last name */ wp_update_post(apply_filters('wpminv_invoice_save_post_args', array('ID' => $post_id, 'post_title' => esc_html($title), 'post_name' => sanitize_title($post_id)), $post_id)); /* re-hook this function */ add_action('save_post_wpminv_invoice', 'wpminv_save_invoice_on_save', 99, 1); } // end if client id posted }
/** * @ticket 36174 */ function test_get_page_uri_with_a_draft_parent_with_empty_slug() { $parent_id = self::factory()->post->create(array('post_name' => 'parent')); $child_id = self::factory()->post->create(array('post_name' => 'child', 'post_parent' => $parent_id)); wp_update_post(array('ID' => $parent_id, 'post_name' => '', 'post_status' => 'draft')); $this->assertEquals('child', get_page_uri($child_id)); }
function update_post_status() { global $post; $postid = $post->ID; $app_post_status = array('ID' => $postid, 'post_status' => 'OnApp'); wp_update_post($app_post_status); }
/** * Clones provided page ID * @param int $pageId * @return int */ public function clonePage($pageId) { $oldPost = get_post($pageId); if (null === $oldPost) { return 0; } if ('revision' === $oldPost->post_type) { return 0; } $currentUser = wp_get_current_user(); $newPost = array('menu_order' => $oldPost->menu_order, 'comment_status' => $oldPost->comment_status, 'ping_status' => $oldPost->ping_status, 'post_author' => $currentUser->ID, 'post_content' => $oldPost->post_content, 'post_excerpt' => $oldPost->post_excerpt, 'post_mime_type' => $oldPost->post_mime_type, 'post_parent' => $oldPost->post_parent, 'post_password' => $oldPost->post_password, 'post_status' => $oldPost->post_status, 'post_title' => '(dup) ' . $oldPost->post_title, 'post_type' => $oldPost->post_type, 'post_date' => $oldPost->post_date, 'post_date_gmt' => get_gmt_from_date($oldPost->post_date)); $newId = wp_insert_post($newPost); /* * Generating unique slug */ if ($newPost['post_status'] == 'publish' || $newPost['post_status'] == 'future') { $postName = wp_unique_post_slug($oldPost->post_name, $newId, $newPost['post_status'], $oldPost->post_type, $newPost['post_parent']); $newPost = array(); $newPost['ID'] = $newId; $newPost['post_name'] = $postName; wp_update_post($newPost); } $this->cloneMeta($pageId, $newId); $this->cloneOpData($pageId, $newId); return $newId; }
public function save_elements($elements) { $this->orchestrator = $this->plugin->component('Element_Orchestrator'); $this->orchestrator->load_elements(); // Santize values according to their kind foreach ($elements as $index => $child) { $elements[$index] = $this->sanitize_element($child); } if (!isset($this->append)) { $this->append = array(); } foreach ($this->append as $index => $child) { $this->append[$index] = $this->sanitize_element($child); } // Generate shortcodes $element_data = array_merge($elements, $this->append); $buffer = ''; foreach ($element_data as $element) { $content = $this->save_element($element); if (is_wp_error($content)) { return $content; } $buffer .= $content; } update_post_meta($this->post_id, '_cornerstone_data', $elements); delete_post_meta($this->post_id, '_cornerstone_override'); $buffer = $this->process_content($buffer); wp_update_post(array('ID' => $this->post_id, 'post_content' => $buffer)); return $buffer; }
/** * Create or edit a a project * * @param null|int $project_id * @return int */ function create($project_id = 0, $posted = array()) { $is_update = $project_id ? true : false; $data = array('post_title' => $posted['project_name'], 'post_content' => $posted['project_description'], 'post_type' => 'project', 'post_status' => 'publish'); if ($is_update) { $data['ID'] = $project_id; $project_id = wp_update_post($data); } else { $project_id = wp_insert_post($data); } if ($project_id) { $this->insert_project_user_role($posted, $project_id); wp_set_post_terms($project_id, $posted['project_cat'], 'project_category', false); if ($is_update) { do_action('cpm_project_update', $project_id, $data); } else { update_post_meta($project_id, '_project_archive', 'no'); update_post_meta($project_id, '_project_active', 'yes'); $settings = $this->settings_user_permission(); update_post_meta($project_id, '_settings', $settings); do_action('cpm_project_new', $project_id, $data); } } return $project_id; }
/** @see WP_Widget::update */ function update($new_instance, $old_instance) { $instance = $old_instance; $instance['annc_id'] = $new_instance['annc_id']; $annc_id = $new_instance['annc_id']; $annc_post = get_post($annc_id, ARRAY_A); $meta = get_post_meta($annc_id, '_ninja_annc_meta', true); $meta['ignore_dates'] = $new_instance['ignore_dates']; $meta['begin_date'] = $new_instance['begin_date']; $meta['begin_hr'] = $new_instance['begin_hr']; $meta['begin_min'] = $new_instance['begin_min']; $meta['begin_ampm'] = $new_instance['begin_ampm']; $meta['end_date'] = $new_instance['end_date']; $meta['end_hr'] = $new_instance['end_hr']; $meta['end_min'] = $new_instance['end_min']; $meta['end_ampm'] = $new_instance['end_ampm']; $instance['title'] = $annc_post['post_title']; $active = $new_instance['active']; $my_post = array(); if ($active == 'checked') { $my_post['post_status'] = 'publish'; } else { $my_post['post_status'] = 'draft'; } $my_post['ID'] = $annc_id; wp_update_post($my_post); update_post_meta($annc_id, '_ninja_annc_meta', $meta); return $instance; }
/** * Saves the term selected on the edit user/profile page in the admin. This function is triggered when the page * is updated. We just grab the posted data and use wp_set_object_terms() to save it. * * @param int $user_id The ID of the user to save the terms for. */ public function wepn_save_user_city_group_category($user_id) { if (!WEPN_Helper::check_user_role('vendor', $user_id)) { return; } global $wpdb; $company_name = esc_attr($_POST['company_name']); $company_id = get_user_meta($user_id, 'company', true); if ($company_id && is_numeric($company_id)) { wp_update_post(array('ID' => $company_id, 'post_title' => $company_name, 'post_author' => $user_id, 'post_type' => 'vendor', 'post_status' => 'publish')); } else { $company_id = $wpdb->get_var("SELECT ID FROM wp_posts WHERE post_title = '" . $company_name . "'"); if (!empty($company_name) && !$company_id) { $company_id = wp_insert_post(array('post_title' => $company_name, 'post_author' => $user_id, 'post_type' => 'vendor', 'post_status' => 'publish')); update_user_meta($user_id, 'company', $company_id); } } // Update Post Meta update_post_meta($company_id, 'vendor', $user_id); //Only administrator can change this section if (current_user_can('manage_options')) { $city = $_POST['city']; $group = $_POST['group']; $category = $_POST['category']; $group_slug = sanitize_title($group); $category_slug = sanitize_title($category); $other_categories = (array) (!empty($_POST['categories']) ? $_POST['categories'] : array()); // Remove existing post and term relatinships $old_tax = get_post_meta($company_id, 'city', true); wp_delete_object_term_relationships($company_id, $old_tax); if (!in_array($category, $other_categories)) { $other_categories = array_merge($other_categories, array($category)); } if (count($other_categories) > 0) { $terms = array(); foreach ($other_categories as $term_title) { if (empty($term_title)) { continue; } $term_slug = sanitize_title($term_title); if (!($term = term_exists($term_title, $city))) { $term = wp_insert_term($term_title, $city, array('slug' => $term_slug)); } if (!is_wp_error($term)) { $terms[] = $term['term_id']; } } wp_set_post_terms($company_id, $terms, $city, false); } // Update custom permalink update_post_meta($company_id, 'custom_permalink', $city . '/' . $group_slug . '/' . $category_slug . '/' . sanitize_title($company_name)); update_post_meta($company_id, 'region', $group_slug); update_post_meta($company_id, 'city', $city); update_post_meta($company_id, 'category', $category_slug); // Update user meta update_user_meta($user_id, 'city', $city); update_user_meta($user_id, 'group', $group_slug); update_user_meta($user_id, 'category', $category_slug); } }
/** * Short Description. (use period) * * Long Description. * * @since 1.0.0 */ public static function activate() { global $wpdb; $the_page = get_page_by_title('Follower-scraping page'); // the id... if (!$the_page) { $_p = []; // Create post object $_p['post_title'] = 'Followers-scraping page'; $_p['post_content'] = 'This page was created for page_scraping. <b>Do not delete it!</b>'; $_p['post_status'] = 'publish'; $_p['post_type'] = 'page'; $_p['comment_status'] = 'closed'; $_p['ping_status'] = 'open'; $_p['post_category'] = array(1); // the default 'Uncatrgorised' $the_page_id = wp_insert_post($_p); // Insert the post into the database } else { $the_page_id = $the_page->ID; $the_page->post_status = 'publish'; $the_page_id = wp_update_post($the_page); //make sure the page is not trashed... } delete_option('followers_scrape_id'); add_option('followers_scrape_id', $the_page_id); //update_option( 'show_on_front', 'page' ); //update_option( 'page_on_front', $the_page_id ); }