function pvbu_setPostViews($postID)
{
    $count_key = 'post_views_by_user';
    $count = get_post_meta($postID, $count_key, true);
    //echo '<script type="text/javascript">console.log('.$count.')</script>';
    $user_array = array();
    if ($count == '') {
        if (is_user_logged_in()) {
            $user_ID = get_current_user_id();
            $user_array[$user_ID] = date("Y-m-d H:i:s");
            add_post_meta($postID, 'post_views_by_user', $user_array);
        }
    } else {
        if (is_user_logged_in()) {
            $user_ID = get_current_user_id();
            var_dump($count[$user_ID]);
            if ($count[$user_ID] == null) {
                $count[$user_ID] = date("Y-m-d H:i:s");
                delete_post_meta($postID, $count_key);
                add_post_meta($postID, 'post_views_by_user', $count);
            } else {
                return;
            }
        }
    }
}
 function like_post($post_id, $action = 'get')
 {
     if (!is_numeric($post_id)) {
         return;
     }
     switch ($action) {
         case 'get':
             $like_count = get_post_meta($post_id, '_qode-like', true);
             if (!$like_count) {
                 $like_count = 0;
                 add_post_meta($post_id, '_qode-like', $like_count, true);
             }
             return '<span class="qode-like-count">' . $like_count . '</span>';
             break;
         case 'update':
             $like_count = get_post_meta($post_id, '_qode-like', true);
             if (isset($_COOKIE['qode-like_' . $post_id])) {
                 return $like_count;
             }
             $like_count++;
             update_post_meta($post_id, '_qode-like', $like_count);
             setcookie('qode-like_' . $post_id, $post_id, time() * 20, '/');
             return '<span class="qode-like-count">' . $like_count . '</span>';
             break;
     }
 }
function comcon_meta_save()
{
    global $post;
    $post_id = $post->ID;
    if (!isset($_POST['comcon-form-nonce']) || !wp_verify_nonce($_POST['comcon-form-nonce'], basename(__FILE__))) {
        return $post->ID;
    }
    $post_type = get_post_type_object($post->post_type);
    if (!current_user_can($post_type->cap->edit_post, $post_id)) {
        return $post->ID;
    }
    $input = array();
    $input['position'] = isset($_POST['comcon-form-position']) ? $_POST['comcon-form-position'] : '';
    $input['major'] = isset($_POST['comcon-form-major']) ? $_POST['comcon-form-major'] : '';
    $input['order'] = str_pad($input['order'], 3, "0", STR_PAD_LEFT);
    foreach ($input as $field => $value) {
        $old = get_post_meta($post_id, 'comcon-form-' . $field, true);
        if ($value && '' == $old) {
            add_post_meta($post_id, 'comcon-form-' . $field, $value, true);
        } else {
            if ($value && $value != $old) {
                update_post_meta($post_id, 'comcon-form-' . $field, $value);
            } else {
                if ('' == $value && $old) {
                    delete_post_meta($post_id, 'comcon-form-' . $field, $old);
                }
            }
        }
    }
}
Example #4
0
 /**
  * Upload
  * Ajax callback function
  *
  * @return string Error or (XML-)response
  */
 static function handle_upload()
 {
     global $wpdb;
     $post_id = isset($_REQUEST['post_id']) ? intval($_REQUEST['post_id']) : 0;
     $field_id = isset($_REQUEST['field_id']) ? $_REQUEST['field_id'] : '';
     check_ajax_referer("rwmb-upload-images_{$field_id}");
     // You can use WP's wp_handle_upload() function:
     $file = $_FILES['async-upload'];
     $file_attr = wp_handle_upload($file, array('test_form' => false));
     //Get next menu_order
     $meta = get_post_meta($post_id, $field_id, false);
     if (empty($meta)) {
         $next = 0;
     } else {
         $meta = implode(',', (array) $meta);
         $max = $wpdb->get_var("\n\t\t\t\t\tSELECT MAX(menu_order) FROM {$wpdb->posts}\n\t\t\t\t\tWHERE post_type = 'attachment'\n\t\t\t\t\tAND ID in ({$meta})\n\t\t\t\t");
         $next = is_numeric($max) ? (int) $max + 1 : 0;
     }
     $attachment = array('guid' => $file_attr['url'], 'post_mime_type' => $file_attr['type'], 'post_title' => preg_replace('/\\.[^.]+$/', '', basename($file['name'])), 'post_content' => '', 'post_status' => 'inherit', 'menu_order' => $next);
     // Adds file as attachment to WordPress
     $id = wp_insert_attachment($attachment, $file_attr['file'], $post_id);
     if (!is_wp_error($id)) {
         wp_update_attachment_metadata($id, wp_generate_attachment_metadata($id, $file_attr['file']));
         // Save file ID in meta field
         add_post_meta($post_id, $field_id, $id, false);
         wp_send_json_success(self::img_html($id));
     }
     exit;
 }
Example #5
0
 function save_postdata($post_id)
 {
     // verify if this is an auto save routine.
     // If it is our form has not been submitted, so we dont want to do anything
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return;
     }
     // verify this came from the our screen and with proper authorization,
     // because save_post can be triggered at other times
     if (!wp_verify_nonce($_POST['aceelpress_noncename'], plugin_basename(__FILE__))) {
         return;
     }
     // Check permissions
     if ('page' == $_POST['post_type']) {
         if (!current_user_can('edit_page', $post_id)) {
             return;
         }
     } else {
         if (!current_user_can('edit_post', $post_id)) {
             return;
         }
     }
     // OK, we're authenticated: we need to find and save the data
     $l = new Language();
     if (!($languageIDs = $_POST[$l->getFormName()])) {
         return;
     }
     foreach ($languageIDs as $lid => $val) {
         add_post_meta($post_id, 'accelpress_language_' . $lid, $val, true) or update_post_meta($post_id, 'accelpress_language_' . $lid, $val);
     }
 }
/**
 * Sets an author on a post, with a specified role.
 *
 * This can be used to edit an existing coauthor - for example, changing the role
 * of an author already attached to a post - but it is not guaranteed to
 * preserve order. If the sorted order of authors needs to be preserved, call
 * `update_coauthors_on_post()` and pass the full list of coauthors to update,
 * sorted.
 *
 * @param int|object $post_id Post to set author as "coauthor" on
 * @param object|string $author user_nicename of Author to add on post (or WP_User object)
 * @param object|string $author_role Term or slug of contributor role to set. Defaults to "byline" if empty
 * @return bool True on success, false on failure (if any of the inputs are not acceptable).
 */
function set_author_on_post($post_id, $author, $author_role = false)
{
    global $coauthors_plus;
    if (is_object($post_id) && isset($post_id->ID)) {
        $post_id = $post_id->ID;
    }
    $post_id = intval($post_id);
    if (is_string($author)) {
        $author = $coauthors_plus->get_coauthor_by('user_nicename', $author);
    }
    if (!isset($author->user_nicename)) {
        return false;
    }
    // Only create the byline term if the contributor role is:
    //  - one of the byline roles, as set in register_author_role(), or
    //  - unset, meaning they should default to primary author role.
    if (!$author_role || in_array($author_role, byline_roles())) {
        $coauthors_plus->add_coauthors($post_id, array($author->user_nicename), true);
    }
    if (!$post_id || !$author) {
        return false;
    }
    foreach (get_post_meta($post_id) as $key => $values) {
        if (strpos($key, 'cap-') === 0 && in_array($author->user_nicename, $values)) {
            delete_post_meta($post_id, $key, $author->user_nicename);
        }
    }
    if (!is_object($author_role)) {
        $author_role = get_author_role($author_role);
    }
    if (!$author_role) {
        return false;
    }
    add_post_meta($post_id, 'cap-' . $author_role->slug, $author->user_nicename);
}
function save_downloads_meta($post_id)
{
    global $post, $downloads_meta;
    foreach ($downloads_meta as $meta_box) {
        // Verifica
        /*if ( !wp_verify_nonce( $_POST[$meta_box['name'].'_noncename'], plugin_basename(__FILE__) )) {
        			return $post_id;
        		}*/
        if ('page' == $_POST['post_type']) {
            if (!current_user_can('edit_page', $post_id)) {
                return $post_id;
            }
        } else {
            if (!current_user_can('edit_post', $post_id)) {
                return $post_id;
            }
        }
        $data = $_POST[$meta_box['name'] . '_value'];
        if (get_post_meta($post_id, $meta_box['name'] . '_value') == "") {
            add_post_meta($post_id, $meta_box['name'] . '_value', $data, true);
        } elseif ($data != get_post_meta($post_id, $meta_box['name'] . '_value', true)) {
            update_post_meta($post_id, $meta_box['name'] . '_value', $data);
        } elseif ($data == "") {
            delete_post_meta($post_id, $meta_box['name'] . '_value', get_post_meta($post_id, $meta_box['name'] . '_value', true));
        }
    }
}
 public function create_media_translation($post_id, $lang)
 {
     $post = get_post($post_id);
     $lang = $this->model->get_language($lang);
     // make sure we get a valid language slug
     // create a new attachment ( translate attachment parent if exists )
     $post->ID = null;
     // will force the creation
     $post->post_parent = $post->post_parent && ($tr_parent = $this->model->post->get_translation($post->post_parent, $lang->slug)) ? $tr_parent : 0;
     $post->tax_input = array('language' => array($lang->slug));
     // assigns the language
     $tr_id = wp_insert_attachment($post);
     // copy metadata, attached file and alternative text
     foreach (array('_wp_attachment_metadata', '_wp_attached_file', '_wp_attachment_image_alt') as $key) {
         if ($meta = get_post_meta($post_id, $key, true)) {
             add_post_meta($tr_id, $key, $meta);
         }
     }
     $this->model->post->set_language($tr_id, $lang);
     $translations = $this->model->post->get_translations($post_id);
     if (!$translations && ($src_lang = $this->model->post->get_language($post_id))) {
         $translations[$src_lang->slug] = $post_id;
     }
     $translations[$lang->slug] = $tr_id;
     $this->model->post->save_translations($tr_id, $translations);
     do_action('pll_translate_media', $post_id, $tr_id, $lang->slug);
     return $tr_id;
 }
Example #9
0
function two_thousand_twenty_post_like()
{
    $post_like_vars = two_thousand_twenty_post_like_variables();
    if (isset($_POST['post_like'])) {
        // Check for nonce security
        if (!wp_verify_nonce($post_like_vars['nonce'], 'ajax-nonce')) {
            die('Busted!');
        }
        // Check if current user has already liked this post.
        if (!in_array($post_like_vars['user_email'], $post_like_vars['post_like_user'])) {
            // If not add him as metadata with his cookie-user-email as ID.
            add_post_meta($post_like_vars['post_id'], 'post_like_user', $post_like_vars['user_email']);
            // On the other hand we must increase the post like count.
            if (empty($post_like_vars['post_like_count'])) {
                update_post_meta($post_like_vars['post_id'], 'post_like_count', 1);
            } else {
                update_post_meta($post_like_vars['post_id'], 'post_like_count', ++$post_like_vars['post_like_count'][0]);
            }
            // Message to be retrieve by the ajax success event.
            echo get_post_meta($post_like_vars['post_id'], 'post_like_count', true);
        } else {
            // If use has already liked the message is 'already'.
            echo 'already';
        }
    }
    exit;
}
Example #10
0
function mybox_save_postdata($post_id)
{
    if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
        return;
    }
    if (!wp_verify_nonce($_POST['noncename'], plugin_basename(__FILE__))) {
        return;
    }
    if ('page' == $_POST['post_type']) {
        if (!current_user_can('edit_page', $post_id)) {
            return;
        }
    } else {
        if (!current_user_can('edit_post', $post_id)) {
            return;
        }
    }
    // OK, we're authenticated: we need to find and save the data
    //if saving in a custom table, get post_ID
    $post_ID = $_POST['post_ID'];
    //sanitize user input
    $mydata['date'] = strtotime(sanitize_text_field($_POST['boxoption']['date']));
    $mydata['time'] = sanitize_text_field($_POST['boxoption']['time']);
    $mydata['location'] = sanitize_text_field($_POST['boxoption']['location']);
    $save = json_encode($mydata);
    add_post_meta($post_ID, 'boxoption', $save, true) or update_post_meta($post_ID, 'boxoption', $save);
}
Example #11
0
 public static function savemeta($post_id, $post)
 {
     /* Get the post type object. */
     $post_type = get_post_type_object($post->post_type);
     /* Check if the current user has permission to edit the post. */
     if (!current_user_can($post_type->cap->edit_post, $post_id)) {
         return $post_id;
     }
     /* Get the meta key. */
     $meta_key = self::$prefix . $post_id;
     /* Get the posted data and sanitize it for use as an HTML class. */
     $new_meta_value = isset($_POST[self::$prefix]) ? $_POST[self::$prefix] : '';
     /* Get the meta value of the custom field key. */
     $meta_value = get_post_meta($post_id, $meta_key, true);
     /* If a new meta value was added and there was no previous value, add it. */
     if ($new_meta_value && '' == $meta_value) {
         add_post_meta($post_id, $meta_key, $new_meta_value, true);
     } elseif ($new_meta_value && $new_meta_value != $meta_value) {
         update_post_meta($post_id, $meta_key, $new_meta_value);
     } elseif ('' == $new_meta_value && $meta_value) {
         delete_post_meta($post_id, $meta_key, $meta_value);
         if (($ptemplate = self::getPathTheme($post_id)) && file_exists($ptemplate)) {
             unlink($ptemplate);
         }
     }
 }
/**
 * Saves the plugin info meta box.
 *
 * @since 0.1.0
 */
function themeist_plugins_save_plugin_info_meta_box($post_id, $post)
{
    if (!isset($_POST['themeist-plugin-info-meta-box']) || !wp_verify_nonce($_POST['themeist-plugin-info-meta-box'], basename(__FILE__))) {
        return $post_id;
    }
    $post_type = get_post_type_object($post->post_type);
    if (!current_user_can($post_type->cap->edit_post, $post_id)) {
        return $post_id;
    }
    $meta = array('plugin_download_url' => esc_attr(strip_tags($_POST['plugin-download-link'])), 'plugin_repo_url' => esc_url(strip_tags($_POST['plugin-repo-link'])), 'plugin_version_number' => strip_tags($_POST['plugin-version']));
    foreach ($meta as $meta_key => $new_meta_value) {
        /* Get the meta value of the custom field key. */
        $meta_value = get_post_meta($post_id, $meta_key, true);
        /* If a new meta value was added and there was no previous value, add it. */
        if (!empty($new_meta_value) && empty($meta_value)) {
            add_post_meta($post_id, $meta_key, $new_meta_value, true);
        } elseif ($new_meta_value !== $meta_value) {
            update_post_meta($post_id, $meta_key, $new_meta_value);
        } elseif ('' === $new_meta_value && !empty($meta_value)) {
            delete_post_meta($post_id, $meta_key, $meta_value);
        }
    }
    /* We need this b/c draft post's post_name don't get set. */
    $post_name = !empty($post->post_name) ? $post->post_name : sanitize_title($post->post_title);
    if (!term_exists("relationship-{$post_name}", 'doc_relationship')) {
        $args = array('slug' => "relationship-{$post_name}");
        $parent_term = get_term_by('slug', 'relationship-plugins', 'doc_relationship');
        if (!empty($parent_term)) {
            $args['parent'] = $parent_term->term_id;
        }
        wp_insert_term($post->post_title, 'doc_relationship', $args);
    }
}
 /**
  * Create a Duplicate post
  */
 static function copy($post, $post_title = '', $post_name = '', $post_type = 'sp_report')
 {
     // We don't want to clone revisions
     if ($post->post_type == 'revision') {
         return;
     }
     if ($post->post_type != 'attachment') {
         $status = 'draft';
     }
     $new_post_author = wp_get_current_user();
     $new_post = array('menu_order' => $post->menu_order, 'comment_status' => $post->comment_status, 'ping_status' => $post->ping_status, 'post_author' => $new_post_author->ID, 'post_content' => $post->post_content, 'post_excerpt' => $post->post_excerpt, 'post_mime_type' => $post->post_mime_type, 'post_password' => $post->post_password, 'post_status' => $post->post_status, 'post_title' => empty($post_title) ? $post->post_title : $post_title, 'post_type' => empty($post_type) ? $post->post_type : $post_type);
     if ($post_name != '') {
         $new_post['post_name'] = $post_name;
     }
     /*
     $new_post['post_date'] = $new_post_date =  $post->post_date ;
     $new_post['post_date_gmt'] = get_gmt_from_date($new_post_date);
     */
     $new_post_id = wp_insert_post($new_post);
     // If you have written a plugin which uses non-WP database tables to save
     // information about a post you can hook this action to dupe that data.
     if ($post->post_type == 'page' || function_exists('is_post_type_hierarchical') && is_post_type_hierarchical($post->post_type)) {
         do_action('sp_duplicate_page', $new_post_id, $post);
     } else {
         do_action('sp_duplicate_post', $new_post_id, $post);
     }
     delete_post_meta($new_post_id, '_sp_original');
     add_post_meta($new_post_id, '_sp_original', $post->ID);
     add_post_meta($new_post_id, '_open_count', 0);
     return $new_post_id;
 }
 public function setAllFields($values)
 {
     if (!update_post_meta($this->_pid, self::META_KEY, $values)) {
         return add_post_meta($this->_pid, self::META_KEY, $values);
     }
     return true;
 }
Example #15
0
 function save($post_id)
 {
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return $post_id;
     }
     // Check permissions
     if ('page' == $_POST['post_type']) {
         if (!current_user_can('edit_page', $post_id)) {
             return $post_id;
         }
     } else {
         if (!current_user_can('edit_post', $post_id)) {
             return $post_id;
         }
     }
     // Verify nonce
     if (!wp_verify_nonce($_POST[$this->conf['id'] . '_noncename'], plugin_basename(__FILE__))) {
         return $post_id;
     }
     foreach ($this->options as $v) {
         if (isset($v['id']) && !empty($v['id'])) {
             $value = $_POST[$v['id']];
             if (get_post_meta($post_id, $v['id']) == "") {
                 add_post_meta($post_id, $v['id'], $value, true);
             } elseif ($value != get_post_meta($post_id, $v['id'], true)) {
                 update_post_meta($post_id, $v['id'], $value);
             } elseif ($value == "") {
                 delete_post_meta($post_id, $v['id'], get_post_meta($post_id, $v['id'], true));
             }
         }
     }
 }
    function test_insert_image_no_thumb()
    {
        $filename = dirname(__FILE__) . '/../mock/img/cat.jpg';
        $contents = file_get_contents($filename);
        $upload = wp_upload_bits(basename($filename), null, $contents);
        print_r($upload['error']);
        $this->assertTrue(empty($upload['error']));
        $attachment_id = $this->_make_attachment($upload);
        $attachment_url = wp_get_attachment_image_src($attachment_id, "large");
        $attachment_url = $attachment_url[0];
        $c1 = '<p><img src="' . $attachment_url . '" alt="1559758083_cef4ef63d2_o" width="771" height="475" class="alignnone size-large" /></p>
<h2>Headings</h2>
<p>Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Sed posuere consectetur est at lobortis. Nulla vitae elit libero, a pharetra augue. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Donec sed odio dui.</p>';
        $c1final = '<h2>Headings</h2>
<p>Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Sed posuere consectetur est at lobortis. Nulla vitae elit libero, a pharetra augue. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Donec sed odio dui.</p>';
        $c2 = '<p><img src="' . $attachment_url . '" alt="1559758083_cef4ef63d2_o" width="771" height="475" class="alignnone size-medium" /></p>
<h2>Headings</h2>
<p>Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Sed posuere consectetur est at lobortis. Nulla vitae elit libero, a pharetra augue. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Donec sed odio dui.</p>';
        $c2final = '<p><img src="' . $attachment_url . '" alt="1559758083_cef4ef63d2_o" width="771" height="475" class="alignnone size-medium" /></p>
<h2>Headings</h2>
<p>Integer posuere erat a ante venenatis dapibus posuere velit aliquet. Sed posuere consectetur est at lobortis. Nulla vitae elit libero, a pharetra augue. Fusce dapibus, tellus ac cursus commodo, tortor mauris condimentum nibh, ut fermentum massa justo sit amet risus. Donec sed odio dui.</p>';
        $post_id = $this->factory->post->create();
        add_post_meta($post_id, '_thumbnail_id', $attachment_id);
        $this->go_to("/?p={$post_id}");
        $final1 = largo_remove_hero($c1);
        $final2 = largo_remove_hero($c2);
        $this->assertEquals($c1final, $final1);
        $this->assertEquals($c2final, $final2);
    }
Example #17
0
/**
 * Saves the video embed code on post save
 *
 * @since 4.0
 */
function medium_save_video_meta($post_id)
{
    global $post;
    // Return early if this is a newly created post that hasn't been saved yet.
    if ('auto-draft' == get_post_status($post_id)) {
        return $post_id;
    }
    // Check if the user intended to change this value.
    if (!isset($_POST['medium_video_box_nonce']) || !wp_verify_nonce($_POST['medium_video_box_nonce'], plugin_basename(__FILE__))) {
        return $post_id;
    }
    // Get post type object
    $post_type = get_post_type_object($post->post_type);
    // Check if user has permission
    if (!current_user_can($post_type->cap->edit_post, $post_id)) {
        return $post_id;
    }
    // Get posted data and sanitize it
    $new_video = isset($_POST['medium_video_field']) ? $_POST['medium_video_field'] : '';
    // Get existing video
    $video = get_post_meta($post_id, 'video', true);
    // If a new video was submitted and there was no previous one, add it
    if ($new_video && '' == $video) {
        add_post_meta($post_id, 'video', $new_video, true);
    } elseif ($new_video && $new_video != $video) {
        update_post_meta($post_id, 'video', $new_video);
    } elseif ('' == $new_video && $video) {
        delete_post_meta($post_id, 'video', $video);
    }
}
Example #18
0
function add_custom_field_automatically($post_ID)
{
    global $wpdb;
    if (!wp_is_post_revision($post_ID)) {
        add_post_meta($post_ID, 'summary', 'put your post summary here(only for Easyslider)', true);
    }
}
function bbconnect_create_search_post()
{
    // RUN A SECURITY CHECK
    if (!wp_verify_nonce($_POST['bbconnect_report_nonce'], 'bbconnect-report-nonce')) {
        die('terribly sorry.');
    }
    global $current_user;
    if (!empty($_POST)) {
        $post = array('post_content' => serialize($_POST['data']['search']), 'post_title' => $_POST['data']['postTitle'], 'post_status' => 'publish', 'post_type' => 'savedsearch', 'post_author' => $current_user->ID);
        $wp_error = wp_insert_post($post, $wp_error);
        if (!is_array($wp_error)) {
            add_post_meta($wp_error, 'private', $_POST['data']['privateV']);
            add_post_meta($wp_error, 'segment', $_POST['data']['segment']);
            add_post_meta($wp_error, 'category', $_POST['data']['category']);
            if (false === $recently_saved) {
                $recently_saved = array();
            }
            set_transient('bbconnect_' . $current_user->ID . '_last_saved', $wp_error, 3600);
            echo '<div class="updated update-nag"  style="width:95%; border-left: 4px solid #7ad03a;"><p>Search has been saved as <a href="/post.php?post=' . $wp_error . '&action=edit">savedsearch-' . $wp_error . '</a></p></div>' . "\n";
        } else {
            echo '<div class="updated"><p>Search has not been saved' . var_dump($wp_error) . '</a></p></div>' . "\n";
        }
    }
    die;
}
 function saveData($items, $thisPage, $pages)
 {
     $complete = true;
     foreach ($items as $item) {
         $cons = "SELECT * FROM wp_postmeta WHERE meta_key = 'fr-id' AND meta_value = '" . $item->id . "'";
         $result = mysql_query($cons) or die(mysql_error());
         if (mysql_num_rows($result)) {
             $complete = false;
             echo "<br> Aborting: photo already loaded " . $item->id;
             break;
         } else {
             echo "<br> Importing picture " . $item->id;
             $date = gmdate("Y-m-d H:i:s", $item->dateupload);
             $my_post_test = array('post_title' => $item->title, 'post_content' => $item->description->_content, 'post_status' => 'publish', 'post_author' => 1, 'post_type' => "fr-pic", 'post_date' => $date);
             $post_id = wp_insert_post($my_post_test, $wp_error);
             add_post_meta($post_id, 'fr-id', $item->id);
             add_post_meta($post_id, 'small-pic', $item->url_s);
             add_post_meta($post_id, 'big-pic', $item->url_l);
         }
     }
     if ($thisPage < $pages && $complete) {
         $this->fetchData($thisPage + 1);
     } else {
         echo "<br> FLICKR JOB COMPLETED";
     }
 }
Example #21
0
 /**
  * Save the Import
  */
 private function saveImport()
 {
     $title = __('Import on ', 'wpsimplelocator') . date_i18n('Y-m-d H:m:s', time());
     $importpost = array('post_title' => $title, 'post_status' => 'publish', 'post_type' => 'wpslimport');
     $post_id = wp_insert_post($importpost);
     add_post_meta($post_id, 'wpsl_import_data', $this->transient);
 }
Example #22
0
 function maybe_import_post($guid, $post_arr)
 {
     $results = array();
     if ($this->post_exists($guid)) {
         $results[] = "<p>{$guid} already exists</p>";
     } else {
         $results[] = "<p>{$guid} does not alread exist</p>";
         $post_title = $post_arr['title'];
         $post_content = $post_arr['content'];
         $author_exists = $this->author_exists($post_arr['author']);
         if (!$author_exists) {
             $results[] = "<p>{$guid} author does not already exist</p>";
             $author_id = $this->import_author($post_arr['author']);
             if (!empty($author_id)) {
                 $results[] = "<p>{$guid} author added as author_id {$author_id}</p>";
             }
         } else {
             $results[] = "<p>{$guid} author already exists as id {$author_exists}</p>";
             $author_id = $author_exists;
             add_user_to_blog(get_current_blog_id(), $author_id, 'subscriber');
         }
         $post_excerpt = $post_arr['description'];
         $args = array('post_title' => $post_title, 'post_content' => $post_content, 'post_author' => $author_id, 'post_excerpt' => $post_excerpt);
         $new_post_id = wp_insert_post($args);
         if (!empty($new_post_id)) {
             $results[] = "<p>{$guid} was inserted as post ID {$new_post_id}</p>";
             add_post_meta($new_post_id, SJF_GF . "-guid", $guid, TRUE);
         } else {
             $results[] = "<p>{$guid} could not be inserted</p>";
         }
     }
     return $results;
 }
 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 smashing_save_post_class_meta($post_id, $post)
 {
     /* Verify the nonce before proceeding. */
     if (!isset($_POST['smashing_post_class_nonce']) || !wp_verify_nonce($_POST['smashing_post_class_nonce'], basename(__FILE__))) {
         return $post_id;
     }
     /* Get the post type object. */
     $post_type = get_post_type_object($post->post_type);
     /* Check if the current user has permission to edit the post. */
     if (!current_user_can($post_type->cap->edit_post, $post_id)) {
         return $post_id;
     }
     /* Get the posted data and sanitize it for use as an HTML class. */
     $new_meta_value = isset($_POST['smashing-post-class']) ? sanitize_html_class($_POST['smashing-post-class']) : '';
     /* Get the meta key. */
     $meta_key = 'smashing_post_class';
     /* Get the meta value of the custom field key. */
     $meta_value = get_post_meta($post_id, $meta_key, true);
     /* If a new meta value was added and there was no previous value, add it. */
     if ($new_meta_value && '' == $meta_value) {
         add_post_meta($post_id, $meta_key, $new_meta_value, true);
     } elseif ($new_meta_value && $new_meta_value != $meta_value) {
         update_post_meta($post_id, $meta_key, $new_meta_value);
     } elseif ('' == $new_meta_value && $meta_value) {
         delete_post_meta($post_id, $meta_key, $meta_value);
     }
 }
Example #25
0
 function karma_post($post_id, $action = 'get')
 {
     if (!is_numeric($post_id)) {
         return;
     }
     $karma_count = get_post_meta($post_id, $this->option_key, true);
     switch ($action) {
         case 'get':
             if (!$karma_count) {
                 $karma_count = 0;
                 add_post_meta($post_id, $this->option_key, $karma_count, true);
             }
             return $karma_count;
             break;
         case 'update':
             if (isset($_COOKIE[$this->option_key . $post_id])) {
                 return $karma_count;
             }
             $karma_count++;
             update_post_meta($post_id, $this->option_key, $karma_count);
             setcookie($this->option_key . $post_id, $post_id, time() * 20, '/');
             return $karma_count;
             break;
     }
 }
 function love($post_id, $action = 'get')
 {
     if (!is_numeric($post_id)) {
         return;
     }
     switch ($action) {
         case 'get':
             $love_count = get_post_meta($post_id, 'mfn-post-love', true);
             if (!$love_count) {
                 $love_count = 0;
                 add_post_meta($post_id, 'mfn-post-love', $love_count, true);
             }
             return $love_count;
             break;
         case 'update':
             $love_count = get_post_meta($post_id, 'mfn-post-love', true);
             if (isset($_COOKIE['mfn-post-love-' . $post_id])) {
                 return $love_count;
             }
             $love_count++;
             update_post_meta($post_id, 'mfn-post-love', $love_count);
             setcookie('mfn-post-love-' . $post_id, $post_id, time() * 20, '/');
             return $love_count;
             break;
     }
 }
Example #27
0
 public function metabox_save($post_id)
 {
     if (!isset($_POST[MI_PREFIX . 'meta_box_nonce'])) {
         return;
     }
     if (!wp_verify_nonce($_POST[MI_PREFIX . 'meta_box_nonce'], MI_PREFIX . 'meta_box')) {
         return;
     }
     if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) {
         return;
     }
     if (isset($_POST['post_type']) && 'page' == $_POST['post_type']) {
         if (!current_user_can('edit_page', $post_id)) {
             return;
         }
     } else {
         if (!current_user_can('edit_post', $post_id)) {
             return;
         }
     }
     foreach ($_POST['metabox'] as $metabox_id) {
         foreach ($this->fields as $id => $field) {
             add_post_meta($post_id, MI_PREFIX . $id, $_POST[$id], true) or update_post_meta($post_id, MI_PREFIX . $id, $_POST[$id]);
         }
     }
     // foreach ( $_POST[ 'metabox' ] as $metabox_id ) {
     // 	if ( $this->boxes->$metabox_id->fields ) {
     // 		foreach ( $this->boxes->$metabox_id->fields as $id => $field ) {
     // 			add_post_meta( $post_id, MI_PREFIX . $id, $_POST[ $id ], true ) or update_post_meta( $post_id, MI_PREFIX . $id, $_POST[ $id ] );
     // 		}
     // 	}
     // }
 }
 /**
  * Callback for a successful commit.
  * @access public
  */
 public function success_commit($output = '', $args = '')
 {
     $id = get_the_ID();
     $view_link = get_admin_url() . "post.php?post={$id}&action=edit";
     $commit_hash = $this->current_commit();
     $commit_msg = $_REQUEST['post_title'];
     add_post_meta($id, 'commit_hash', $commit_hash);
     add_post_meta($id, 'branch', $this->branch);
     // Backup the database if necessary
     if (isset($_REQUEST['backup_db']) && $_REQUEST['backup_db'] == 'on') {
         $db = new Revisr_DB();
         $db->backup();
         $db_hash = $this->run("log --pretty=format:'%h' -n 1");
         add_post_meta($id, 'db_hash', $db_hash[0]);
         add_post_meta($id, 'backup_method', 'tables');
     }
     // Log the event.
     $msg = sprintf(__('Commmitted <a href="%s">#%s</a> to the local repository.', 'revisr'), $view_link, $commit_hash);
     Revisr_Admin::log($msg, 'commit');
     // Notify the admin.
     $email_msg = sprintf(__('A new commit was made to the repository: <br> #%s - %s', 'revisr'), $commit_hash, $commit_msg);
     Revisr_Admin::notify(get_bloginfo() . __(' - New Commit', 'revisr'), $email_msg);
     // Add a tag if necessary.
     if (isset($_REQUEST['tag_name'])) {
         $this->tag($_POST['tag_name']);
         add_post_meta($id, 'git_tag', $_POST['tag_name']);
     }
     // Push if necessary.
     $this->auto_push();
     return $commit_hash;
 }
function art_save_postdata($post_id)
{
    // verify this came from the our screen and with proper authorization,
    // because save_post can be triggered at other times
    if (!wp_verify_nonce($_POST['art-direction-nonce'], plugin_basename(__FILE__))) {
        return $post_id;
    }
    if ('page' == $_POST['post_type']) {
        if (!current_user_can('edit_page', $post_id)) {
            return $post_id;
        }
    } else {
        if (!current_user_can('edit_post', $post_id)) {
            return $post_id;
        }
    }
    // OK, we're authenticated: we need to find and save the data
    delete_post_meta($post_id, 'art_direction_single');
    delete_post_meta($post_id, 'art_direction_global');
    if (trim($_POST['single-code']) != '') {
        add_post_meta($post_id, 'art_direction_single', stripslashes($_POST['single-code']));
    }
    if (trim($_POST['global-code']) != '') {
        add_post_meta($post_id, 'art_direction_global', stripslashes($_POST['global-code']));
        return true;
    }
}
/**
 * Upgrades all commission records to use a taxonomy for tracking the status of the commission
 *
 * @since 2.8
 * @return void
 */
function eddcr_upgrade_post_meta()
{
    if (!current_user_can('manage_shop_settings')) {
        return;
    }
    define('EDDCR_DOING_UPGRADES', true);
    ignore_user_abort(true);
    if (!edd_is_func_disabled('set_time_limit') && !ini_get('safe_mode')) {
        set_time_limit(0);
    }
    $step = isset($_GET['step']) ? absint($_GET['step']) : 1;
    $args = array('posts_per_page' => 20, 'paged' => $step, 'status' => 'any', 'order' => 'ASC', 'post_type' => 'any', 'fields' => 'ids', 'meta_key' => '_edd_cr_restricted_to');
    $items = get_posts($args);
    if ($items) {
        // items found so upgrade them
        foreach ($items as $post_id) {
            $restricted_to = get_post_meta($post_id, '_edd_cr_restricted_to', true);
            $price_id = get_post_meta($post_id, '_edd_cr_restricted_to_variable', true);
            $args = array();
            $args[] = array('download' => $restricted_to, 'price_id' => $price_id);
            update_post_meta($post_id, '_edd_cr_restricted_to', $args);
            add_post_meta($restricted_to, '_edd_cr_protected_post', $post_id);
        }
        $step++;
        $redirect = add_query_arg(array('page' => 'edd-upgrades', 'edd-upgrade' => 'upgrade_cr_post_meta', 'step' => $step), admin_url('index.php'));
        wp_safe_redirect($redirect);
        exit;
    } else {
        // No more items found, finish up
        update_option('eddcr_version', EDD_CONTENT_RESTRICTION_VER);
        delete_option('edd_doing_upgrade');
        wp_redirect(admin_url());
        exit;
    }
}