public function fetch($client_id, $tag) { global $wpdb; $instagram = new \Instagram\Instagram(); $instagram->setClientId($client_id); $min_tag_id = get_option("last_instagram_tag_{$tag}_id", 0); $tag = $instagram->getTag($tag); $media = $tag->getMedia(array('min_tag_id' => $min_tag_id)); update_option("last_instagram_tag_{$tag}_id", $media->getNextMaxTagId()); foreach ($media as $m) { $query = "SELECT posts.* FROM " . $wpdb->posts . " AS posts\n INNER JOIN " . $wpdb->postmeta . " AS wpostmeta ON wpostmeta.post_id = posts.ID\n AND wpostmeta.meta_key = 'degg_instagram_id'\n AND wpostmeta.meta_value = '{$m->getID()}'"; $posts = $wpdb->get_results($query, ARRAY_A); if (!$posts) { $id = wp_insert_post(array('post_title' => "{$m->getUser()} on {$m->getCreatedTime('M jS Y @ g:ia')}", 'post_content' => "<img src='{$m->getThumbnail()->url}' title='Posted by {$m->getUser()} on {$m->getCreatedTime('M jS Y @ g:ia')}'>", 'post_type' => 'degg_instagram')); add_post_meta($id, 'degg_instagram_id', "{$m->getID()}", true); add_post_meta($id, 'degg_instagram_title', "Posted by {$m->getUser()} on {$m->getCreatedTime('M jS Y @ g:ia')}", true); add_post_meta($id, 'degg_instagram_user', "{$m->getUser()}", true); add_post_meta($id, 'degg_instagram_caption', "{$m->getCaption()}", true); add_post_meta($id, 'degg_instagram_link', "{$m->getLink()}", true); add_post_meta($id, 'degg_instagram_thumbnail', $m->getThumbnail(), true); add_post_meta($id, 'degg_instagram_standard_res', $m->getStandardRes(), true); add_post_meta($id, 'degg_instagram_low_res', $m->getLowRes(), true); wp_publish_post($id); } } }
function manager_admin_init() { if (isset($_POST['key']) && $_POST['key'] == "ioamediamanager") { $type = $_POST['type']; switch ($type) { case "create": $slider_title = $_POST['value']; $slider_post = array('post_title' => $slider_title, 'post_type' => 'slider'); $id = wp_insert_post($slider_post); echo "\r\n\r\n\t\t\t\t\t\t<div class='slider-item clearfix'>\r\n\t\t\t\t\t\t\t \t\t<a href='" . admin_url() . "admin.php?page=ioamed&edit_id={$id}' class='edit-icon pencil-3icon- ioa-front-icon'></a>\r\n\t\t\t\t\t\t\t \t\t<h6>" . $slider_title . "</h6>\r\n\t\t\t\t\t\t\t \t\t<span class='shortcode'> " . __('Shortcode', 'ioa') . " [slider id='{$id}'] </span>\r\n\t\t\t\t\t\t\t\t\t\t<a href='{$id}' class='close cancel-circled-2icon- ioa-front-icon'></a>\r\n\t\t\t\t\t\t</div> \r\n\t\t\t\t\t"; break; case "update": $id = $_POST['id']; $ioa_options = $slides = ''; if (isset($_POST['options'])) { $ioa_options = $_POST['options']; } if (isset($_POST['slides'])) { $slides = $_POST['slides']; } wp_publish_post($id); update_post_meta($id, "options", $ioa_options); update_post_meta($id, "slides", $slides); break; case "delete": $id = $_POST['id']; wp_delete_post($id, true); } die; } }
function test_updating_post_sets_do_not_send_subscription_flag() { $post_id = $this->factory->post->create(); // Publish and then immediately update the post, which should set the do not send flag wp_publish_post($post_id); wp_update_post(array('ID' => $post_id, 'post_content' => 'The updated post content')); $this->assertEquals('1', get_post_meta($post_id, '_jetpack_dont_email_post_to_subs', true)); }
public function test_sync_post_status_change() { $this->assertNotEquals('draft', $this->post->post_status); wp_update_post(array('ID' => $this->post->ID, 'post_status' => 'draft')); $this->sender->do_sync(); $remote_post = $this->server_replica_storage->get_post($this->post->ID); $this->assertEquals('draft', $remote_post->post_status); wp_publish_post($this->post->ID); $this->sender->do_sync(); $remote_post = $this->server_replica_storage->get_post($this->post->ID); $this->assertEquals('publish', $remote_post->post_status); }
function test_pmp_on_post_status_transition() { $pmp_posts = pmp_get_pmp_posts(); $pmp_post = $pmp_posts[0]; $custom_fields = get_post_custom($pmp_post->ID); $date = date('Y-m-d H:i:s', strtotime($custom_fields['pmp_published'][0])); // Transition to published wp_publish_post($pmp_post->ID); $pmp_post_after_transition = get_post($pmp_post->ID); // The date should be the same as the original PMP published date, not the current date/time. $this->assertEquals($pmp_post_after_transition->post_date, $date); }
function ProjectTheme_qq_main_listing_submit_respo() { if ($_POST['qpstat'] == '000') { $md5 = $_POST['md5check']; if (!empty($md5)) { $tranid = $_GET['tranid']; $gr = get_option('LST_QUICKPAY_' . $tranid, true); //****************************** $c = explode('|', $gr); $pid = $c[0]; $uid = $c[1]; $datemade = $c[2]; //--------------------------------------------------- global $wpdb; $pref = $wpdb->prefix; //-------------------------------------------- update_post_meta($pid, "paid", "1"); update_post_meta($pid, "paid_listing_date", current_time('timestamp', 0)); update_post_meta($pid, "closed", "0"); //-------------------------------------------- update_post_meta($pid, 'base_fee_paid', '1'); $featured = get_post_meta($pid, 'featured', true); if ($featured == "1") { update_post_meta($pid, 'featured_paid', '1'); } $private_bids = get_post_meta($pid, 'private_bids', true); if ($private_bids == "1") { update_post_meta($pid, 'private_bids_paid', '1'); } $hide_project = get_post_meta($pid, 'hide_project', true); if ($hide_project == "1") { update_post_meta($pid, 'hide_project_paid', '1'); } //-------------------------------------------- do_action('ProjectTheme_moneybookers_listing_response', $pid); $projectTheme_admin_approves_each_project = get_option('projectTheme_admin_approves_each_project'); if ($projectTheme_admin_approves_each_project != "yes") { wp_publish_post($pid); $post_new_date = date('Y-m-d h:s', current_time('timestamp', 0)); $post_info = array("ID" => $pid, "post_date" => $post_new_date, "post_date_gmt" => $post_new_date, "post_status" => "publish"); wp_update_post($post_info); ProjectTheme_send_email_posted_project_approved($pid); ProjectTheme_send_email_posted_project_approved_admin($pid); } else { ProjectTheme_send_email_posted_project_not_approved($pid); ProjectTheme_send_email_posted_project_not_approved_admin($pid); ProjectTheme_send_email_subscription($pid); } //****************************** } } }
/** * Published scheduled posts that miss their schedule */ public function force_publish_missed_schedules() { global $wpdb; $missed_posts = $wpdb->get_col($wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_status = 'future' AND post_date <= %s LIMIT 25;", current_time('mysql', false))); if (!empty($missed_posts)) { foreach ($missed_posts as $missed_post) { $missed_post = absint($missed_post); wp_publish_post($missed_post); wp_clear_scheduled_hook('publish_future_post', array($missed_post)); do_action('a8c_cron_control_published_post_that_missed_schedule', $missed_post); } } }
function test_publishing_and_unpublishing_posts() { $post_id = $this->factory->post->create(array('post_title' => 'test post', 'post_name' => 'test-post', 'post_status' => 'draft')); SP_API()->post('_refresh'); $this->assertEmpty($this->search_and_get_field(array('query' => 'test post'))); wp_publish_post($post_id); SP_API()->post('_refresh'); $this->assertEquals(array('test-post'), $this->search_and_get_field(array('query' => 'test post'))); $post = array('ID' => $post_id, 'post_status' => 'draft'); wp_update_post($post); SP_API()->post('_refresh'); $this->assertEmpty($this->search_and_get_field(array('query' => 'test post'))); }
public static function publish_missed_schedule() { global $wpdb; $scheduled_ids = $wpdb->get_col("SELECT `ID` FROM `{$wpdb->posts}` WHERE( ((`post_date`>0)&&(`post_date`<=CURRENT_TIMESTAMP())) OR ((`post_date_gmt`>0)&&(`post_date_gmt`<=UTC_TIMESTAMP())) )AND `post_status` = 'future' LIMIT 0, 10"); if (false == $scheduled_ids) { return false; } foreach ($scheduled_ids as $scheduled_id) { if (!$scheduled_id) { continue; } remove_action('publish_future_post', 'check_and_publish_future_post'); wp_publish_post($scheduled_id); add_action('publish_future_post', 'check_and_publish_future_post'); } return true; }
function ProjectTheme_payfast_main_listing_response_payment() { $c = $_POST['custom_str1']; $c = explode('|', $c); $pid = $c[0]; $uid = $c[1]; $datemade = $c[2]; //--------------------------------------------------- global $wpdb; $pref = $wpdb->prefix; //-------------------------------------------- update_post_meta($pid, "paid", "1"); update_post_meta($pid, "paid_listing_date", current_time('timestamp', 0)); update_post_meta($pid, "closed", "0"); //-------------------------------------------- update_post_meta($pid, 'base_fee_paid', '1'); $featured = get_post_meta($pid, 'featured', true); if ($featured == "1") { update_post_meta($pid, 'featured_paid', '1'); } $private_bids = get_post_meta($pid, 'private_bids', true); if ($private_bids == "1") { update_post_meta($pid, 'private_bids_paid', '1'); } $hide_project = get_post_meta($pid, 'hide_project', true); if ($hide_project == "1") { update_post_meta($pid, 'hide_project_paid', '1'); } //-------------------------------------------- do_action('ProjectTheme_moneybookers_listing_response', $pid); $projectTheme_admin_approves_each_project = get_option('projectTheme_admin_approves_each_project'); if ($projectTheme_admin_approves_each_project != "yes") { wp_publish_post($pid); $post_new_date = date('Y-m-d h:s', current_time('timestamp', 0)); $post_info = array("ID" => $pid, "post_date" => $post_new_date, "post_date_gmt" => $post_new_date, "post_status" => "publish"); wp_update_post($post_info); ProjectTheme_send_email_posted_project_approved($pid); ProjectTheme_send_email_posted_project_approved_admin($pid); } else { ProjectTheme_send_email_posted_project_not_approved($pid); ProjectTheme_send_email_posted_project_not_approved_admin($pid); ProjectTheme_send_email_subscription($pid); } //--------------------------- }
function wpms_init() { remove_action('publish_future_post', 'check_and_publish_future_post'); $last = get_option(WPMS_OPTION, false); if ($last !== false && $last > time() - WPMS_DELAY * 60) { return; } update_option(WPMS_OPTION, time()); global $wpdb; $scheduledIDs = $wpdb->get_col("SELECT`ID`FROM`{$wpdb->posts}`" . "WHERE(" . "((`post_date`>0)&&(`post_date`<=CURRENT_TIMESTAMP()))OR" . "((`post_date_gmt`>0)&&(`post_date_gmt`<=UTC_TIMESTAMP()))" . ")AND`post_status`='future'LIMIT 0,5"); if (!count($scheduledIDs)) { return; } foreach ($scheduledIDs as $scheduledID) { if (!$scheduledID) { continue; } wp_publish_post($scheduledID); } }
function tdomf_publish_post($post_ID, $use_queue = true) { $form_id = get_post_meta($post_ID, TDOMF_KEY_FORM_ID, true); $post =& get_post($post_ID); if ($post->post_status == 'future') { // updating the post when the post is already queued wont' work // we need to use the publish post option wp_publish_post($post_ID); } else { $current_ts = current_time('mysql'); $ts = tdomf_queue_date($form_id, $current_ts); if ($current_ts == $ts || !$use_queue) { $post = array("ID" => $post_ID, "post_status" => 'publish'); } else { tdomf_log_message("Future Post Date = {$ts}!"); $post = array("ID" => $post_ID, "post_status" => 'future', "post_date" => $ts, "edit_date" => $ts); } // use update_post as this was the most consistent function since // wp2.2 for publishign the post correctly wp_update_post($post); } }
function manager_admin_init() { if (isset($_GET['page']) && $_GET['page'] == 'ioapty') { wp_enqueue_media(); } if (isset($_POST['key']) && $_POST['key'] == "custompostsmanager") { $type = $_POST['type']; switch ($type) { case "create": $cp_title = $_POST['value']; $cp_post = array('post_title' => $cp_title, 'post_type' => 'custompost'); $id = wp_insert_post($cp_post); echo "\r\n\t\t\t\t\t\t<div class='cp-item clearfix'>\r\n\t\t\t\t\t\t\t \t\t<a href='" . admin_url() . "admin.php?page=ioapty&edit_id={$id}' class='edit-icon pencil-3icon- ioa-front-icon'></a>\r\n\t\t\t\t\t\t\t \t\t<h6>" . $cp_title . "</h6>\r\n\t\t\t\t\t\t\t\t\t\t<a href='{$id}' class='close cancel-circled-2icon- ioa-front-icon'></a>\r\n\t\t\t\t\t\t</div> \r\n\t\t\t\t\t"; break; case "update": $id = $_POST['id']; $ioa_options = $metaboxes = ''; if (isset($_POST['options'])) { $ioa_options = $_POST['options']; } if (isset($_POST['metaboxes'])) { $metaboxes = $_POST['metaboxes']; } $title = $_POST['title']; global $helper; $helper->setPostTitle($title, $id); wp_publish_post($id); update_post_meta($id, "options", $ioa_options); echo update_post_meta($id, "metaboxes", $metaboxes); break; case "delete": $id = $_POST['id']; wp_delete_post($id, true); } die; } }
set_post_format(intval($token), 'gallery'); $attachment = array('guid' => $target_file, 'post_mime_type' => $file_type, 'post_title' => preg_replace('/\\.[^.]+$/', '', $target_file), 'post_content' => '', 'post_status' => 'inherit'); $attach_id = wp_insert_attachment($attachment, $target_file, intval($token)); // Make sure that this file is included, as wp_generate_attachment_metadata() depends on it. require_once ABSPATH . 'wp-admin/includes/image.php'; // Generate the metadata for the attachment, and update the database record. $attach_data = wp_generate_attachment_metadata($attach_id, $target_file); wp_update_attachment_metadata($attach_id, $attach_data); //set_post_thumbnail( intval($token), $attach_id ); if ($attach_id !== 0) { $attachments = get_attached_media("image", intval($token)); foreach ($attachments as $attachment) { array_push($attachments_ids, $attachment->ID); } } if (isset($attachments_ids) && sizeof($attachments_ids) !== 0) { if (get_post(intval($token))->post_status == 'pending') { wp_publish_post(intval($token)); if (!has_post_thumbnail(intval($token))) { set_post_thumbnail(intval($token), $attachments_ids[0]); } } update_field('featured_gallery', $attachments_ids, intval($token)); update_post_meta(intval($token), '_featured_gallery', ''); update_post_meta(intval($token), '_featured_gallery', 'field_5287d441bb41b'); } } } } } }
/** * Save home page */ function siteorigin_panels_save_home_page() { if (!isset($_POST['_sopanels_home_nonce']) || !wp_verify_nonce($_POST['_sopanels_home_nonce'], 'save')) { return; } if (!current_user_can('edit_theme_options')) { return; } if (!isset($_POST['panels_data'])) { return; } // Check that the home page ID is set and the home page exists $page_id = get_option('page_on_front'); if (empty($page_id)) { $page_id = get_option('siteorigin_panels_home_page_id'); } $post_content = wp_unslash($_POST['post_content']); if (!$page_id || get_post_meta($page_id, 'panels_data', true) == '') { // Lets create a new page $page_id = wp_insert_post(array('post_title' => __('Home Page', 'siteorigin-panels'), 'post_status' => !empty($_POST['siteorigin_panels_home_enabled']) ? 'publish' : 'draft', 'post_type' => 'page', 'post_content' => $post_content, 'comment_status' => 'closed')); update_option('page_on_front', $page_id); update_option('siteorigin_panels_home_page_id', $page_id); // Action triggered when creating a new home page through the custom home page interface do_action('siteorigin_panels_create_home_page', $page_id); } else { // `wp_insert_post` does it's own sanitization, but it seems `wp_update_post` doesn't. $post_content = sanitize_post_field('post_content', $post_content, $page_id, 'db'); // Update the post with changed content to save revision if necessary. wp_update_post(array('ID' => $page_id, 'post_content' => $post_content)); } // Save the updated page data $panels_data = json_decode(wp_unslash($_POST['panels_data']), true); $panels_data['widgets'] = siteorigin_panels_process_raw_widgets($panels_data['widgets']); $panels_data = siteorigin_panels_styles_sanitize_all($panels_data); update_post_meta($page_id, 'panels_data', $panels_data); $template = get_post_meta($page_id, '_wp_page_template', true); $home_template = siteorigin_panels_setting('home-template'); if (($template == '' || $template == 'default') && !empty($home_template)) { // Set the home page template update_post_meta($page_id, '_wp_page_template', $home_template); } if (!empty($_POST['siteorigin_panels_home_enabled'])) { update_option('show_on_front', 'page'); update_option('page_on_front', $page_id); update_option('siteorigin_panels_home_page_id', $page_id); wp_publish_post($page_id); } else { // We're disabling this home page update_option('show_on_front', 'posts'); // Change the post status to draft $post = get_post($page_id); if ($post->post_status != 'draft') { global $wpdb; $wpdb->update($wpdb->posts, array('post_status' => 'draft'), array('ID' => $post->ID)); clean_post_cache($post->ID); $old_status = $post->post_status; $post->post_status = 'draft'; wp_transition_post_status('draft', $old_status, $post); do_action('edit_post', $post->ID, $post); do_action("save_post_{$post->post_type}", $post->ID, $post, true); do_action('save_post', $post->ID, $post, true); do_action('wp_insert_post', $post->ID, $post, true); } } }
/** * Tests that changing the document slug is reflected in permalinks */ function test_document_slug() { global $wp_rewrite; $tdr = new WP_Test_Document_Revisions(); //set new slug update_site_option('document_slug', 'docs'); //add doc and flush $docID = $tdr->test_add_document(); wp_publish_post($docID); wp_cache_flush(); $this->verify_download(get_permalink($docID), $tdr->test_file, 'revised document slug permalink doesn\'t rewrite'); $this->assertContains('/docs/', get_permalink($docID), 'revised document slug not in permalink'); }
/** * Process the bulk actions */ public function process_bulk_action() { $ids = isset($_GET['post']) ? $_GET['post'] : false; $action = $this->current_action(); if (!is_array($ids)) { $ids = array($ids); } if (empty($action)) { return; } foreach ($ids as $id) { // Detect when a bulk action is being triggered... if ('trash' === $this->current_action()) { wp_trash_post($id); } if ('publish' === $this->current_action()) { wp_publish_post($id); } if ('pending' === $this->current_action()) { // Update post $u_post = array(); $u_post['ID'] = $id; $u_post['post_status'] = 'pending'; // Update the post into the database wp_update_post($u_post); } if ('delete' === $this->current_action()) { wp_delete_post($id, true); } if ('restore' === $this->current_action()) { wp_untrash_post($id); } do_action('ap_moderate_table_do_bulk_action', $id, $this->current_action()); } }
/** * Function definition is based on core of https://wordpress.org/plugins/wp-missed-schedule/ */ public function publish_missed_schedule_posts($post_id) { global $wpdb; $publish_missed_schedule_posts_response = array(); try { $post_date = current_time('mysql', 0); $publish_missed_schedule_posts_response['post_date'] = $post_date; if (is_numeric($post_id)) { $qry = "SELECT ID FROM {$wpdb->posts} WHERE ID = %d AND ( ( post_date > 0 && post_date <= %s ) ) AND post_status = 'future' LIMIT 1"; $sql = $wpdb->prepare($qry, $post_id, $post_date); } else { $qry = "SELECT ID FROM {$wpdb->posts} WHERE ( ( post_date > 0 && post_date <= %s ) ) AND post_status = 'future' LIMIT 0,10"; $sql = $wpdb->prepare($qry, $post_date); } //log('SQL: ' . $sql); $post_ids = $wpdb->get_col($sql); $count_missed_schedule = count($post_ids); $publish_missed_schedule_posts_response['count_missed_schedule'] = $count_missed_schedule; if ($count_missed_schedule > 0) { $publish_missed_schedule_posts_response['missed_schedule_post_ids'] = $post_ids; foreach ($post_ids as $post_id) { if (!$post_id) { continue; } // !!! LET THE MAGIC HAPPEN !!! // wp_publish_post($post_id); } } } catch (Exception $e) { $publish_missed_schedule_posts_response['exception'] = $e->getMessage(); } return $publish_missed_schedule_posts_response; }
function delibera_nova_pauta_create_action() { $opt = delibera_get_config(); if ($opt['criar_pauta_pelo_front_end'] == 'S' && is_user_logged_in() && isset($_POST['_wpnonce']) && wp_verify_nonce($_POST['_wpnonce'], 'delibera_nova_pauta')) { $title = $_POST['nova-pauta-titulo']; $content = $_POST['nova-pauta-conteudo']; $excerpt = $_POST['nova-pauta-resumo']; $pauta = array(); $pauta['post_title'] = $title; $pauta['post_excerpt'] = $excerpt; $pauta['post_type'] = 'pauta'; //Check if there is any file uploaded // If there is any, then ignore 'content' and use File. // else do add 'pauta' with the text content if (!empty($_FILES['post_pdf_contribution']['name'])) { // Setup the array of supported file types. In this case, it's just PDF. $supported_types = array('application/pdf'); // Get the file type of the upload $pdf_contribution = wp_check_filetype(basename($_FILES['post_pdf_contribution']['name'])); $sent_file_type = $pdf_contribution['type']; // Check if the type is supported. If not, throw an error. if (!in_array($sent_file_type, $supported_types)) { //TODO: Improve this message and avoid wp_die wp_die("O arquivo para web não é um PDF (formato permitido)."); } $uploaded_file = wp_upload_bits($_FILES['pauta_pdf_contribution']['name'], null, file_get_contents($_FILES['pauta_pdf_contribution']['tmp_name'])); if (isset($uploaded_file['error']) && $uploaded_file['error'] != 0) { wp_die('Erro ao salvar arquivo para Web. O erro foi: ' . $upload['error']); } else { $pauta['pauta_pdf_contribution'] = $uploaded_file['url']; } } else { $pauta['post_content'] = $content; } // para que a situação da pauta seja criada corretamente, // é necessário criar a pauta como rascunho para depois publicar no final desta função $pauta['post_status'] = 'draft'; $pauta_id = wp_insert_post($pauta); if (is_int($pauta_id) && $pauta_id > 0) { /* Os valores adicionados ao array $_POST são baseados no if da função delibera_save_post(), * comentado abaixo if( ( // Se tem validação, tem que ter o prazo $opt['validacao'] == 'N' || (array_key_exists('prazo_validacao', $_POST) && array_key_exists('min_validacoes', $_POST) ) ) && ( // Se tem relatoria, tem que ter o prazo $opt['relatoria'] == 'N' || array_key_exists('prazo_relatoria', $_POST) ) && ( // Se tem relatoria, e é preciso eleger o relator, tem que ter o prazo para eleição $opt['relatoria'] == 'N' || ( $opt['eleicao_relator'] == 'N' || array_key_exists('prazo_eleicao_relator', $_POST) ) ) && array_key_exists('prazo_discussao', $_POST) && array_key_exists('prazo_votacao', $_POST) ) */ if ($opt['validacao'] == 'S') { $_POST['prazo_validacao'] = date('d/m/Y', strtotime('+' . $opt['dias_validacao'] . ' DAYS')); $_POST['min_validacoes'] = $opt['minimo_validacao']; } if ($opt['relatoria'] == 'S') { $_POST['prazo_relatoria'] = date('d/m/Y', strtotime('+' . $opt['dias_relatoria'] . ' DAYS')); if ($opt['eleicao_relator'] == 'S') { $_POST['prazo_eleicao_relator'] = date('d/m/Y', strtotime('+' . $opt['dias_votacao_relator'] . ' DAYS')); } } if (trim($opt['data_fixa_nova_pauta_externa']) != '') { $prazo_discussao = DateTime::createFromFormat('d/m/Y', $opt['data_fixa_nova_pauta_externa']); $_POST['prazo_discussao'] = $prazo_discussao->format('d/m/Y'); $_POST['prazo_votacao'] = date('d/m/Y', strtotime('+' . $opt['dias_votacao'] . ' DAYS', $prazo_discussao->getTimestamp())); } else { $_POST['prazo_discussao'] = date('d/m/Y', strtotime('+' . $opt['dias_discussao'] . ' DAYS')); $_POST['prazo_votacao'] = date('d/m/Y', strtotime('+' . $opt['dias_votacao'] . ' DAYS')); } // isto é necessário por causa do if da função delibera_publish_pauta() $_POST['publish'] = 'Publicar'; $_POST['prev_status'] = 'draft'; // verifica se todos os temas enviados por post são válidos $temas = get_terms('tema', array('hide_empty' => true)); $temas_ids = array(); if (isset($_POST['tema']) && is_array($_POST['tema'])) { foreach ($temas as $tema) { if (in_array($tema->term_id, $_POST['tema'])) { $temas_ids[] = $tema->term_id; } } } // coloca os termos de temas no post wp_set_post_terms($pauta_id, $temas_ids, 'tema'); // publica o post wp_publish_post($pauta_id); // isto serve para criar o slug corretamente, // já que no wp_insert_post não cria o slug quando o status é draft e o wp_publish_post tb não cria o slug unset($pauta['post_status']); $pauta['ID'] = $pauta_id; $pauta['post_name'] = sanitize_post_field('post_name', $title, $pauta_id, 'save'); wp_update_post($pauta); // redireciona para a pauta criada $permalink = get_post_permalink($pauta_id); wp_safe_redirect($permalink); die; } } }
/** * check_and_publish_future_post() - check to make sure post has correct status before * passing it on to be published. Invoked by cron 'publish_future_post' event * This safeguard prevents cron from publishing drafts, etc. * * {@internal Missing Long Description}} * * @package WordPress * @subpackage Post * @since 2.5 * @uses $wpdb * * @param int $post_id Post ID * @return int|null {@internal Missing Description}} */ function check_and_publish_future_post($post_id) { $post = get_post($post_id); if (empty($post)) { return; } if ('future' != $post->post_status) { return; } return wp_publish_post($post_id); }
/** * Auto setup settings. * * Fires after a membership setup is completed. * This hook is executed every time a new membership is created. * * Related Action Hooks: * - ms_controller_membership_setup_completed * * @since 1.0.0 * * @param MS_Model_Membership $membership */ public function auto_setup_settings($membership) { $settings = $this->get_model(); // Create special pages. MS_Model_Pages::create_missing_pages(); $pg_prot_cont = MS_Model_Pages::get_page(MS_Model_Pages::MS_PAGE_PROTECTED_CONTENT); $pg_acco = MS_Model_Pages::get_page(MS_Model_Pages::MS_PAGE_ACCOUNT); $pg_regi = MS_Model_Pages::get_page(MS_Model_Pages::MS_PAGE_REGISTER); $pg_regi_comp = MS_Model_Pages::get_page(MS_Model_Pages::MS_PAGE_REG_COMPLETE); $pg_memb = MS_Model_Pages::get_page(MS_Model_Pages::MS_PAGE_MEMBERSHIPS); // Publish special pages. // Tip: Only pages must be published that are added to the menu. wp_publish_post($pg_acco->ID); if (!$membership->private) { wp_publish_post($pg_memb->ID); wp_publish_post($pg_regi->ID); } // Create new WordPress menu-items. MS_Model_Pages::create_menu(MS_Model_Pages::MS_PAGE_ACCOUNT); if (!$membership->private) { MS_Model_Pages::create_menu(MS_Model_Pages::MS_PAGE_MEMBERSHIPS); MS_Model_Pages::create_menu(MS_Model_Pages::MS_PAGE_REGISTER); } // Enable Membership2. $settings->plugin_enabled = true; $settings->save(); // Enable the "Allow user registration" setting of WordPress MS_Model_Member::allow_registration(); }
function post_action() { //Read form data $action = $_POST['action']; $postId = $_POST['id']; if ('publish' === $action) { wp_publish_post($postId); } else { if ('update' === $action) { $postData = $_POST['post_data']; $my_post = is_array($postData) ? $postData : array(); wp_update_post($my_post); } else { if ('unpublish' === $action) { $my_post = array(); $my_post['ID'] = $postId; $my_post['post_status'] = 'draft'; wp_update_post($my_post); } else { if ('trash' === $action) { add_action('trash_post', array('MainWP_Child_Links_Checker', 'hook_post_deleted')); wp_trash_post($postId); } else { if ('delete' === $action) { add_action('delete_post', array('MainWP_Child_Links_Checker', 'hook_post_deleted')); wp_delete_post($postId, true); } else { if ('restore' === $action) { wp_untrash_post($postId); } else { if ('update_meta' === $action) { $values = maybe_unserialize(base64_decode($_POST['values'])); $meta_key = $values['meta_key']; $meta_value = $values['meta_value']; $check_prev = $values['check_prev']; foreach ($meta_key as $i => $key) { if (1 === intval($check_prev[$i])) { update_post_meta($postId, $key, get_post_meta($postId, $key, true) ? get_post_meta($postId, $key, true) : $meta_value[$i]); } else { update_post_meta($postId, $key, $meta_value[$i]); } } } else { $information['status'] = 'FAIL'; } } } } } } } if (!isset($information['status'])) { $information['status'] = 'SUCCESS'; } $information['my_post'] = $my_post; MainWP_Helper::write($information); }
update_post_meta($pid, 'private_bids_paid', '1'); } $hide_project = get_post_meta($pid, 'hide_project', true); if ($hide_project == "1" or $hide_project == "yes") { update_post_meta($pid, 'hide_project_paid', '1'); } $ProjectTheme_get_images_cost_extra = ProjectTheme_get_images_cost_extra($pid); $image_fee_paid = get_post_meta($pid, 'image_fee_paid', true); update_post_meta($pid, 'image_fee_paid', $image_fee_paid + $ProjectTheme_get_images_cost_extra); //-------------------------------------------- do_action('ProjectTheme_paypal_listing_response', $pid); $projectTheme_admin_approves_each_project = get_option('projectTheme_admin_approves_each_project'); $paid_listing_date = get_post_meta($pid, 'paid_listing_date_paypal' . $datemade, true); if (empty($paid_listing_date)) { if ($projectTheme_admin_approves_each_project != "yes") { wp_publish_post($pid); $xx = current_time('timestamp', 0); $post_pr_new_date = date('Y-m-d H:i:s', $xx); $gmt = get_gmt_from_date($xx); $post_pr_info = array("ID" => $pid, "post_date" => $post_pr_new_date, "post_date_gmt" => $gmt, "post_status" => "publish"); wp_update_post($post_pr_info); ProjectTheme_send_email_posted_project_approved($pid); ProjectTheme_send_email_posted_project_approved_admin($pid); } else { ProjectTheme_send_email_posted_project_not_approved($pid); ProjectTheme_send_email_posted_project_not_approved_admin($pid); ProjectTheme_send_email_subscription($pid); } update_post_meta($pid, "paid_listing_date_paypal" . $datemade, current_time('timestamp', 0)); } }
/** * Creates any missing Membership pages. * * @since 1.0.0 * @return array|false Titles of the created pages */ public static function create_missing_pages() { static $Done = false; $res = false; if ($Done) { return $res; } $Done = true; $user_id = get_current_user_id(); if (empty($user_id)) { return $res; } $types = self::get_page_types(); $res = array(); $site_id = self::get_setting('site_id'); MS_Factory::select_blog($site_id); foreach ($types as $type => $title) { $page_id = self::get_setting($type); $status = get_post_status($page_id); if (!$status || 'trash' == $status) { // Page does not exist or was deleted. Create new page. $page_id = 0; } elseif ('publish' != $status) { // The page exists but is not published. Publish now. wp_publish_post($page_id); } // If the post_id does not exist then create a new page if (empty($page_id)) { $data = array('post_title' => $title, 'post_name' => $type, 'post_content' => self::get_default_content($type), 'post_type' => 'page', 'post_status' => 'publish', 'post_author' => $user_id); $new_id = wp_insert_post($data); /** * Filter the new page_id * * @since 1.0.0 */ $new_id = apply_filters('ms_model_pages_create_missing_page', $new_id, $type, $data); if (is_numeric($new_id)) { self::set_setting($type, $new_id); $res[$new_id] = $title; /** * Trigger action to allow modifications to the page * * @since 1.0.0 */ do_action('ms_model_pages_create_wp_page', $new_id); } } } MS_Factory::revert_blog(); return apply_filters('ms_model_pages_create_missing_page', $res); }
/** * Listens for permalink_query_arg and inserts into new post * note: being run on admin_title hook because must be afer $post is established * but before headers are sent so it can redirect */ function callback_handler($title) { global $post; global $pagenow; if (!$post || !$pagenow || !isset($_GET[$this->permalink_query_arg])) { return $title; } //cap check if (!current_user_can('edit_posts')) { return $title; } $permalink = apply_filters('storify_permalink', $_GET[$this->permalink_query_arg]); do_action('storify_edit', $permalink, $post->ID, $post); //updating an existing post, no need to continue if ($pagenow != 'post-new.php') { return $title; } //make API call to get story title and description $story = $this->get_story($permalink, true); //API call failed, can't continue if (!$story) { wp_die(__('An error occurred while publishing the story', 'storify')); } //the returned permalink is valid, the given may not be $post->post_content = apply_filters('storify_callback_permalink', $story->permalink, $story, $post->ID); //api call failed, don't cause errors if (isset($story->title)) { $post->post_title = $story->title; $post->post_name = $story->title; } //set tags if we've got 'em and this is a post if ($post->post_type == 'post' && !empty($story->hashtags) && apply_filters('storify_add_tags', true, $story, $post)) { wp_set_post_tags($post->ID, $story->hashtags); } //save changes wp_update_post($post); $msg = 1; //user can publish, publish and set proper message //note: external devs can filter storify_auto_publish, returning false, to prevent publishing if (current_user_can('publish_posts') && apply_filters('storify_auto_publish', true)) { wp_publish_post($post->ID); $msg = 6; } do_action('storify_publish', $permalink, $post->ID, $post, $msg); //we just published or drafted, so redirect user to post.php, not post-new, and add proper message wp_redirect(admin_url('post.php?post=' . $post->ID . '&action=edit&message=' . $msg)); exit; }
function publish_future_post_now($id) { // Set new post's post_status to "publish" rather than "future." if (!empty($_POST["post_type"]) && $_POST["post_type"] == "event") { wp_publish_post($id); } }
public function do_frequently() { global $wpdb; print "WPEngine Frequent Periodic Tasks: Start\n"; // Check for old wp-cron items that aren't clearing out. Has to be older than a certain // threshold because that means we've done several wp-cron attempts and it's not clearing. // Also only clear certain known problematic things which might be gumming up other non-problematic // things, e.g. Disqus was doing this as a known issue on Nicekicks. if (true) { $now = time(); $problematic_wp_cron_hooks = array('dsq_sync_post', 'dsq_sync_forum'); // bad types $problematic_wp_cron_age_secs = 60 * 60 * 2; // when older than this, delete the entries. $too_old = $now - $problematic_wp_cron_age_secs; // if scheduled timestamp older than this, it needs to be nuked. $crons = _get_cron_array(); if (!empty($crons)) { print "\tLoaded crons array, contains " . count($crons) . " entries.\n"; $changed_cron = FALSE; // did we make any changes? foreach ($crons as $timestamp => $cron) { if ($timestamp < $too_old) { // ancient! foreach ($problematic_wp_cron_hooks as $hook) { // only nuke these if (isset($crons[$timestamp][$hook])) { $changed_cron = true; print "\tRemoved old cron: {$hook}: {$timestamp}: age=" . ($now - $timestamp) . " s\n"; unset($crons[$timestamp][$hook]); } } if (empty($crons[$timestamp])) { // any timestamp with no hooks can always be deleted $changed_cron = true; unset($crons[$timestamp]); } } } if ($changed_cron) { // don't re-write cron unless something actually changed, otherwise *very* inefficient! print "\tRe-writing crons array, now contains " . count($crons) . " entries.\n"; _set_cron_array($crons); } } } // Check for "future" posts (i.e. scheduled) which missed the schedule. This happens on high-traffic // sites when in the middle of a cron job because there's just a single-shot cron event for that post. $sql = $wpdb->prepare("SELECT ID FROM {$wpdb->posts} WHERE post_status = %s AND post_date_gmt < UTC_TIMESTAMP()", 'future'); $post_ids = $wpdb->get_col($sql); foreach ($post_ids as $post_id) { print "\tFIXING: Post ID {$post_id} was scheduled but was missed. Publishing now...\n"; wp_publish_post($post_id); print "\t\tFIXED.\n"; } print "Finished.\n"; }
/** * Ajax handler for quickly approving faqs * * Allows an admin to quickly approve a FAQ * By clicking the appropriate link * from the post row actions * * @since 3.0.0 */ function approve_woo_faq() { //the posted post id $post_id = absint($_POST['post_id']); //initialize our results array $result = array(); //todo: move this cap to product author if (!current_user_can('publish_post', $post_id)) { wp_send_json_error(array('message' => __('Current user does not have permissions over this post', 'woocommerce-faqs'))); } //verify the posted nonce if (!wp_verify_nonce($_POST['nonce'], 'publish-post_' . $post_id)) { wp_send_json_error(array('message' => __('Cheatin’ uh?'))); } //if we got this far, publish the post and generate the success wp_publish_post($post_id); $result['message'] = __('Approved...reloading now.', 'woocommerce-faqs'); $result['redirect'] = admin_url('edit.php?post_type=' . WOOFAQS_POST_TYPE); wp_send_json_success($result); }
/** * Publish future post and make sure post ID has future post status. * * Invoked by cron 'publish_future_post' event. This safeguard prevents cron * from publishing drafts, etc. * * @since 2.5.0 * * @param int $post_id Post ID. * @return null Nothing is returned. Which can mean that no action is required or post was published. */ function check_and_publish_future_post($post_id) { $post = get_post($post_id); if (empty($post)) { return; } if ('future' != $post->post_status) { return; } $time = strtotime($post->post_date_gmt . ' GMT'); if ($time > time()) { // Uh oh, someone jumped the gun! wp_clear_scheduled_hook('publish_future_post', array($post_id)); // clear anything else in the system wp_schedule_single_event($time, 'publish_future_post', array($post_id)); return; } return wp_publish_post($post_id); }
/** * Save home page */ function siteorigin_panels_save_home_page() { if (!isset($_POST['_sopanels_home_nonce']) || !wp_verify_nonce($_POST['_sopanels_home_nonce'], 'save')) { return; } if (!current_user_can('edit_theme_options')) { return; } // Check that the home page ID is set and the home page exists $page_id = get_option('page_on_front'); if (empty($page_id)) { $page_id = get_option('siteorigin_panels_home_page_id'); } if (!$page_id || get_post_meta($page_id, 'panels_data', true) == '') { // Lets create a new page $page_id = wp_insert_post(array('post_title' => __('Home Page', 'siteorigin-panels'), 'post_status' => $_POST['siteorigin_panels_home_enabled'] == 'true' ? 'publish' : 'draft', 'post_type' => 'page', 'comment_status' => 'closed')); update_option('page_on_front', $page_id); update_option('siteorigin_panels_home_page_id', $page_id); } // Save the updated page data $panels_data = json_decode(wp_unslash($_POST['panels_data']), true); $panels_data['widgets'] = siteorigin_panels_process_raw_widgets($panels_data['widgets']); $panels_data = siteorigin_panels_styles_sanitize_all($panels_data); update_post_meta($page_id, 'panels_data', $panels_data); update_post_meta($page_id, '_wp_page_template', siteorigin_panels_setting('home-template')); if (!empty($_POST['siteorigin_panels_home_enabled'])) { update_option('show_on_front', 'page'); update_option('page_on_front', $page_id); update_option('siteorigin_panels_home_page_id', $page_id); wp_publish_post($page_id); } else { // We're disabling this home page update_option('show_on_front', 'posts'); // Change the post status to draft $post = get_post($page_id); if ($post->post_status != 'draft') { global $wpdb; $wpdb->update($wpdb->posts, array('post_status' => 'draft'), array('ID' => $post->ID)); clean_post_cache($post->ID); $old_status = $post->post_status; $post->post_status = 'draft'; wp_transition_post_status('draft', $old_status, $post); do_action('edit_post', $post->ID, $post); do_action("save_post_{$post->post_type}", $post->ID, $post, true); do_action('save_post', $post->ID, $post, true); do_action('wp_insert_post', $post->ID, $post, true); } } }