Exemple #1
0
 public static function resolveWordPressPostToModel(\WP_Post $post)
 {
     /** @var PostTypeManager $postTypes */
     $postTypes = app('posts.types');
     if ($class = $postTypes->get($post->post_type)) {
         return with(new $class())->newInstance($post->to_array());
     }
     return false;
 }
Exemple #2
0
 /**
  * {@inheritdoc}
  */
 public function normalize($blogId, \WP_Post $post)
 {
     $out = $post->to_array();
     unset($out['post_category'], $out['tags_input']);
     $out['terms'] = $this->buildTerms($post);
     if (!empty($post->post_author)) {
         $out['post_author'] = $this->buildAuthor($post);
     }
     return $out;
 }
 public function get($post_id)
 {
     if ($post = \WP_Post::get_instance($post_id)) {
         return $this->wordpress_post_factory->createFromWP_Post(\WP_Post::get_instance($post_id));
     }
     return null;
 }
Exemple #4
0
 /**
  *
  * @return \WP_Post
  */
 public function getWPPost()
 {
     if (null === $this->wpPost) {
         $this->wpPost = \WP_Post::get_instance($this->ID);
     }
     return $this->wpPost;
 }
Exemple #5
0
 public static function getInstance($pid)
 {
     $post = new self($pid);
     $post->setPost(\WP_Post::get_instance($pid));
     $post->fetch();
     return $post;
 }
Exemple #6
0
 /**
  * Use this method to prevent excluding something that was not configured by FakerPress
  *
  * @param  array|int|\WP_Post $post The ID for the Post or the Object
  * @return bool
  */
 public static function delete($post)
 {
     if (is_array($post)) {
         $deleted = array();
         foreach ($post as $id) {
             $id = $id instanceof \WP_Post ? $id->ID : $id;
             if (!is_numeric($id)) {
                 continue;
             }
             $deleted[$id] = self::delete($id);
         }
         return $deleted;
     }
     if (is_numeric($post)) {
         $post = \WP_Post::get_instance($post);
     }
     if (!$post instanceof \WP_Post) {
         return false;
     }
     $flag = (bool) get_post_meta($post->ID, self::$flag, true);
     if (true !== $flag) {
         return false;
     }
     return wp_delete_post($post->ID, true);
 }
 private static function output_term($term_slug, $fallback_text = '')
 {
     $post = WP_Post::get_instance(wskl_get_option('members_page_' . $term_slug));
     if (!$post) {
         echo $fallback_text;
     } else {
         echo '<h3>' . esc_html($post->post_title) . '</h3>';
         echo wpautop(wptexturize($post->post_content));
     }
 }
Exemple #8
0
 private function _handleDataAndSettingsPage()
 {
     if ($_SERVER['REQUEST_METHOD'] == 'POST' && wp_verify_nonce(filter_input(INPUT_GET, 'nonce'))) {
         if ($this->_chart->post_status == 'auto-draft') {
             $this->_chart->post_status = 'publish';
             wp_update_post($this->_chart->to_array());
         }
         update_post_meta($this->_chart->ID, Visualizer_Plugin::CF_SETTINGS, $_POST);
         $render = new Visualizer_Render_Page_Send();
         $render->text = sprintf('[visualizer id="%d"]', $this->_chart->ID);
         wp_iframe(array($render, 'render'));
         return;
     }
     $data = $this->_getChartArray();
     $sidebar = '';
     $sidebar_class = 'Visualizer_Render_Sidebar_Type_' . ucfirst($data['type']);
     if (class_exists($sidebar_class, true)) {
         $sidebar = new $sidebar_class($data['settings']);
         $sidebar->__series = $data['series'];
         $sidebar->__data = $data['data'];
     } else {
         $sidebar = apply_filters("visualizer_pro_chart_type_sidebar", '', $data);
         if ($sidebar != '') {
             $sidebar->__series = $data['series'];
             $sidebar->__data = $data['data'];
         }
     }
     unset($data['settings']['width'], $data['settings']['height']);
     wp_enqueue_style('visualizer-frame');
     wp_enqueue_style('wp-color-picker');
     wp_enqueue_style('visualizer-frame');
     wp_enqueue_script('visualizer-preview');
     wp_enqueue_script('visualizer-render');
     wp_localize_script('visualizer-render', 'visualizer', array('l10n' => array('remotecsv_prompt' => esc_html__('Please, enter the URL of CSV file:', Visualizer_Plugin::NAME), 'invalid_source' => esc_html__('You have entered invalid URL. Please, insert proper URL.', Visualizer_Plugin::NAME)), 'charts' => array('canvas' => $data)));
     $render = new Visualizer_Render_Page_Data();
     $render->chart = $this->_chart;
     $render->type = $data['type'];
     $render->sidebar = $sidebar;
     if (filter_input(INPUT_GET, 'library', FILTER_VALIDATE_BOOLEAN)) {
         $render->button = filter_input(INPUT_GET, 'action') == Visualizer_Plugin::ACTION_EDIT_CHART ? esc_html__('Save Chart', Visualizer_Plugin::NAME) : esc_html__('Create Chart', Visualizer_Plugin::NAME);
     } else {
         $render->button = esc_attr__('Insert Chart', Visualizer_Plugin::NAME);
     }
     if (defined('Visualizer_Pro')) {
         global $Visualizer_Pro;
         $Visualizer_Pro->_enqueueScriptsAndStyles($data);
     }
     $this->_addAction('admin_head', 'renderFlattrScript');
     wp_iframe(array($render, 'render'));
 }
 /**
  * Work with the specifed event object or else use a placeholder if we are in
  * the middle of creating a new event.
  *
  * @param null $event
  */
 protected function get_event($event = null)
 {
     if (is_null($event)) {
         $event = $GLOBALS['post'];
     }
     if (is_numeric($event)) {
         $event = WP_Post::get_instance($event);
     }
     if ($event instanceof stdClass || is_array($event)) {
         $event = new WP_Post((object) $event);
     }
     if (!$event instanceof WP_Post) {
         $event = new WP_Post((object) array('ID' => 0));
     }
     $this->event = $event;
 }
 /**
  * Give_Donate_Form constructor.
  *
  * @since 1.0
  *
  * @param bool  $_id
  * @param array $_args
  */
 public function __construct($_id = false, $_args = array())
 {
     if (false === $_id) {
         $defaults = array('post_type' => 'give_forms', 'post_status' => 'draft', 'post_title' => __('New Give Form', 'give'));
         $args = wp_parse_args($_args, $defaults);
         $_id = wp_insert_post($args, true);
     }
     $donate_form = WP_Post::get_instance($_id);
     if (!is_object($donate_form)) {
         return false;
     }
     if (!is_a($donate_form, 'WP_Post')) {
         return false;
     }
     if ('give_forms' !== $donate_form->post_type) {
         return false;
     }
     foreach ($donate_form as $key => $value) {
         $this->{$key} = $value;
     }
 }
 public function user_register_observer($user_id)
 {
     global $wpdb;
     if (get_option('rf_bonus_signup', 'no') == 'no') {
         return;
     }
     $user_data = get_userdata($user_id);
     $lead_data = array();
     $email = $user_data->data->user_email;
     // var_dump($user_data->data);
     $customer_name = '';
     $lastname = get_user_meta($user_id, 'last_name', 'true');
     $firstname = get_user_meta($user_id, 'first_name', 'true');
     $customer_name = $firstname . ' ' . $lastname;
     if (!trim($customer_name)) {
         $customer_name = $user_data->data->display_name;
     }
     //whether the new registered customer is refer by friend
     $query = "SELECT post.ID as id from  {$wpdb->posts} as  post \n\t\t\n\t\t LEFT JOIN {$wpdb->postmeta} AS rf ON (post.ID = rf.post_id \n\t     and rf.meta_key='rf_invite_email' )\n\t     \n\t     LEFT JOIN {$wpdb->postmeta} AS rf_aff ON (post.ID = rf.post_id \n\t     and rf_aff.meta_key='rf_reward_email' )\n\t     \n\t     WHERE post.post_type = 'mg_referfriend'\n\t     AND rf.meta_value = '{$email}'\n\t\t ";
     $row = $wpdb->get_row($query, ARRAY_A);
     if ($row) {
         $post_id = $row['id'];
         if (get_post_meta($post_id, 'is_rewarded_signup', true) != 'yes') {
             $post = WP_Post::get_instance($post_id);
             $affilate_user_id = $post->post_author;
             $user_data = get_userdata($affilate_user_id);
             $affilate_name = '';
             $lastname = get_user_meta($user_id, 'last_name', 'true');
             $firstname = get_user_meta($user_id, 'first_name', 'true');
             $affilate_name = $firstname . ' ' . $lastname;
             if (!$affilate_name) {
                 $affilate_name = $user_data->data->display_name;
             }
             $affiliate_email = get_post_meta($post_id, 'rf_reward_email', true);
             $this->reward_affiliate('sign_up', $affilate_name, $affiliate_email, $email, 0, array(), array());
             update_post_meta($post_id, 'is_rewarded_signup', 'yes');
         }
     }
 }
Exemple #12
0
 /**
  * Verify if users has the option to hide the Attendees list, applys a good filter
  *
  * @param  int|WP_Post  $post
  * @return boolean
  */
 public static function is_hidden_on($post)
 {
     if (is_numeric($post)) {
         $post = WP_Post::get_instance($post);
     }
     if (!$post instanceof WP_Post) {
         return false;
     }
     $is_hidden = get_post_meta($post->ID, self::HIDE_META_KEY, true);
     // By default non-existent meta will be an empty string
     if ('' === $is_hidden) {
         $is_hidden = true;
     } else {
         $is_hidden = (bool) $is_hidden;
     }
     /**
      * Use this to filter and hide the Attendees List for a specific post or all of them
      *
      * @param bool $is_hidden
      * @param WP_Post $post
      */
     return apply_filters('tribe_tickets_plus_hide_attendees_list', $is_hidden, $post);
 }
 public static function send_email(array &$recipients, $post_id, WSKL_Inactive_Accounts_Shortcodes $shortcodes)
 {
     $post = WP_Post::get_instance($post_id);
     if (!$post) {
         error_log("\$post (ID: {$post_id}) returned false. Notification halted.");
         return;
     }
     $success_count = 0;
     $failure_count = 0;
     /** @var WP_User|array|string $recipient if it is an array, 'name', and 'addr' keys are set. */
     foreach ($recipients as $recipient) {
         $shortcodes->set_recipient($recipient);
         $address = self::get_recipient_address($recipient);
         $subject = do_shortcode($post->post_title);
         $message = wptexturize(wpautop(do_shortcode($post->post_content)));
         if (wp_mail($address, $subject, $message)) {
             ++$success_count;
         } else {
             ++$failure_count;
         }
     }
     error_log("Message sent to {$success_count} users. {$failure_count} failed.");
 }
Exemple #14
0
 /**
  * Get a post object that represents a field group.
  *
  * @param int|string|WP_Post $field_group Numeric ID of the post, post slug or a post object.
  *
  * @return null|WP_Post Requested post object when the post exists and has correct post type. Null otherwise.
  */
 protected final function get_post($field_group)
 {
     $fg_post = null;
     // http://stackoverflow.com/questions/2559923/shortest-way-to-check-if-a-variable-contains-positive-integer-using-php
     if (is_scalar($field_group) && $field_group == (int) $field_group && (int) $field_group > 0) {
         $fg_post = WP_Post::get_instance($field_group);
     } else {
         if (is_string($field_group)) {
             $query = new WP_Query(array('post_type' => $this->get_post_type(), 'name' => $field_group, 'posts_per_page' => 1));
             if ($query->have_posts()) {
                 $fg_post = $query->get_posts();
                 $fg_post = $fg_post[0];
             }
         } else {
             $fg_post = $field_group;
         }
     }
     if ($fg_post instanceof WP_Post && $this->get_post_type() == $fg_post->post_type) {
         return $fg_post;
     } else {
         return null;
     }
 }
Exemple #15
0
 /**
  * Handles chart settigns page.
  *
  * @since 1.0.0
  *
  * @access private
  */
 private function _handleSettingsPage()
 {
     if ($_SERVER['REQUEST_METHOD'] == 'POST' && wp_verify_nonce(filter_input(INPUT_GET, 'nonce'))) {
         if ($this->_chart->post_status == 'auto-draft') {
             $this->_chart->post_status = 'publish';
             wp_update_post($this->_chart->to_array());
         }
         update_post_meta($this->_chart->ID, Visualizer_Plugin::CF_SETTINGS, $_POST);
         $render = new Visualizer_Render_Page_Send();
         $render->text = sprintf('[visualizer id="%d"]', $this->_chart->ID);
         wp_iframe(array($render, 'render'));
         return;
     }
     $data = $this->_getChartArray();
     $sidebar = '';
     $sidebar_class = 'Visualizer_Render_Sidebar_Type_' . ucfirst($data['type']);
     if (class_exists($sidebar_class, true)) {
         $sidebar = new $sidebar_class($data['settings']);
         $sidebar->__series = $data['series'];
         $sidebar->__data = $data['data'];
     }
     unset($data['settings']['width'], $data['settings']['height']);
     wp_enqueue_style('wp-color-picker');
     wp_enqueue_style('visualizer-frame');
     wp_enqueue_script('visualizer-preview');
     wp_localize_script('visualizer-render', 'visualizer', array('charts' => array('canvas' => $data)));
     $render = new Visualizer_Render_Page_Settings();
     $render->sidebar = $sidebar;
     if (filter_input(INPUT_GET, 'library', FILTER_VALIDATE_BOOLEAN)) {
         $render->button = filter_input(INPUT_GET, 'action') == Visualizer_Plugin::ACTION_EDIT_CHART ? esc_html__('Save Chart', Visualizer_Plugin::NAME) : esc_html__('Create Chart', Visualizer_Plugin::NAME);
     } else {
         $render->button = esc_attr__('Insert Chart', Visualizer_Plugin::NAME);
     }
     $this->_addAction('admin_head', 'renderFlattrScript');
     wp_iframe(array($render, 'render'));
 }
 /**
  * A Excerpt method used across the board on our Events Plugin Suite.
  *
  * By default it removes all shortcodes, the reason for this is that shortcodes added by other plugins/themes
  * may not have been registered by the time our ajax responses are generated. To avoid leaving unparsed
  * shortcodes in our excerpts then we strip out anything that looks like one.
  *
  * @category Events
  *
  * @param  WP_Post|int|null $post The Post Object|ID, if null defaults to `get_the_ID()`
  * @param  array $allowed_html The wp_kses compatible array
  *
  * @return string|null Will return null on Bad Post Instances
  */
 function tribe_events_get_the_excerpt($post = null, $allowed_html = null)
 {
     // If post is not numeric or instance of WP_Post it defaults to the current Post ID
     if (!is_numeric($post) && !$post instanceof WP_Post) {
         $post = get_the_ID();
     }
     // If not a WP_Post we try to fetch it as one
     if (is_numeric($post)) {
         $post = WP_Post::get_instance($post);
     }
     // Prevent Non usable $post instances
     if (!$post instanceof WP_Post) {
         return null;
     }
     // Default Allowed HTML
     if (!is_array($allowed_html)) {
         $base_attrs = array('class' => array(), 'id' => array(), 'style' => array());
         $allowed_html = array('a' => array('class' => array(), 'id' => array(), 'style' => array(), 'href' => array(), 'rel' => array(), 'target' => array()), 'b' => $base_attrs, 'strong' => $base_attrs, 'em' => $base_attrs, 'span' => $base_attrs, 'ul' => $base_attrs, 'li' => $base_attrs, 'ol' => $base_attrs);
     }
     /**
      * Allow developers to filter what are the allowed HTML on the Excerpt
      *
      * @var array Must be compatible to wp_kses structure
      *
      * @link https://codex.wordpress.org/Function_Reference/wp_kses
      */
     $allowed_html = apply_filters('tribe_events_excerpt_allowed_html', $allowed_html, $post);
     /**
      * Allow shortcodes to be Applied on the Excerpt or not
      *
      * @var bool
      */
     $allow_shortcode = apply_filters('tribe_events_excerpt_allow_shortcode', false);
     // Get the Excerpt or content based on what is available
     if (has_excerpt($post->ID)) {
         $excerpt = $post->post_excerpt;
     } else {
         $excerpt = $post->post_content;
     }
     // Remove all shortcode Content before removing HTML
     if (!$allow_shortcode) {
         $excerpt = preg_replace('#\\[.+\\]#U', '', $excerpt);
     }
     // Remove "all" HTML based on what is allowed
     $excerpt = wp_kses($excerpt, $allowed_html);
     // Still treat this as an Excerpt on WP
     $excerpt = wp_trim_excerpt($excerpt);
     return wpautop($excerpt);
 }
 public static function get_instance($post_id)
 {
     return WP_Post::get_instance($post_id);
 }
Exemple #18
0
 /**
  * Returns the GCal export link for a given event id.
  *
  * @param int|WP_Post|null $post The Event Post Object or ID, if left empty will give get the current post.
  *
  * @return string The URL for the GCal export link.
  */
 public function googleCalendarLink($post = null)
 {
     if (is_null($post)) {
         $post = self::postIdHelper($post);
     }
     if (is_numeric($post)) {
         $post = WP_Post::get_instance($post);
     }
     if (!$post instanceof WP_Post) {
         return false;
     }
     // After this point we know that we have a safe WP_Post object
     // Fetch if the Event is a Full Day Event
     $is_all_day = Tribe__Date_Utils::is_all_day(get_post_meta($post->ID, '_EventAllDay', true));
     // Fetch the required Date TimeStamps
     $start_date = Tribe__Events__Timezones::event_start_timestamp($post->ID);
     // Google Requires that a Full Day event end day happens on the next Day
     $end_date = Tribe__Events__Timezones::event_end_timestamp($post->ID) + ($is_all_day ? DAY_IN_SECONDS : 0);
     if ($is_all_day) {
         $dates = date('Ymd', $start_date) . '/' . date('Ymd', $end_date);
     } else {
         $dates = date('Ymd', $start_date) . 'T' . date('Hi00', $start_date) . '/' . date('Ymd', $end_date) . 'T' . date('Hi00', $end_date);
     }
     // Fetch the
     $location = trim($this->fullAddressString($post->ID));
     $event_details = apply_filters('the_content', get_the_content($post->ID));
     // Hack: Add space after paragraph
     // Normally Google Cal understands the newline character %0a
     // And that character will automatically replace newlines on urlencode()
     $event_details = str_replace('</p>', '</p> ', $event_details);
     $event_details = strip_tags($event_details);
     //Truncate Event Description and add permalink if greater than 996 characters
     if (strlen($event_details) > 996) {
         $event_url = get_permalink($post->ID);
         $event_details = substr($event_details, 0, 996);
         //Only add the permalink if it's shorter than 900 characters, so we don't exceed the browser's URL limits
         if (strlen($event_url) < 900) {
             $event_details .= sprintf(esc_html__(' (View Full %1$s Description Here: %2$s)', 'the-events-calendar'), $this->singular_event_label, $event_url);
         }
     }
     $params = array('action' => 'TEMPLATE', 'text' => urlencode(strip_tags($post->post_title)), 'dates' => $dates, 'details' => urlencode($event_details), 'location' => urlencode($location), 'trp' => 'false', 'sprop' => 'website:' . home_url());
     $timezone = Tribe__Events__Timezones::get_event_timezone_string($post->ID);
     $timezone = Tribe__Events__Timezones::maybe_get_tz_name($timezone);
     // If we have a good timezone string we setup it; UTC doesn't work on Google
     if (false !== $timezone) {
         $params['ctz'] = urlencode($timezone);
     }
     /**
      * Allow users to Filter our Google Calendar Link params
      * @var array Params used in the add_query_arg
      * @var int   Event ID
      */
     $params = apply_filters('tribe_google_calendar_parameters', $params, $post->ID);
     $base_url = 'http://www.google.com/calendar/event';
     $url = add_query_arg($params, $base_url);
     return $url;
 }
 /**
  * A Excerpt method used across the board on our Events Plugin Suite.
  *
  * By default it removes all shortcodes, the reason for this is that shortcodes added by other plugins/themes
  * may not have been registered by the time our ajax responses are generated. To avoid leaving unparsed
  * shortcodes in our excerpts then we strip out anything that looks like one.
  *
  * @category Events
  *
  * @param  WP_Post|int|null $post The Post Object|ID, if null defaults to `get_the_ID()`
  * @param  array $allowed_html The wp_kses compatible array
  *
  * @return string|null Will return null on Bad Post Instances
  */
 function tribe_events_get_the_excerpt($post = null, $allowed_html = null)
 {
     // If post is not numeric or instance of WP_Post it defaults to the current Post ID
     if (!is_numeric($post) && !$post instanceof WP_Post) {
         $post = get_the_ID();
     }
     // If not a WP_Post we try to fetch it as one
     if (is_numeric($post)) {
         $post = WP_Post::get_instance($post);
     }
     // Prevent Non usable $post instances
     if (!$post instanceof WP_Post) {
         return null;
     }
     // Default Allowed HTML
     if (!is_array($allowed_html)) {
         $base_attrs = array('class' => array(), 'id' => array(), 'style' => array());
         $allowed_html = array('a' => array('class' => array(), 'id' => array(), 'style' => array(), 'href' => array(), 'rel' => array(), 'target' => array()), 'b' => $base_attrs, 'strong' => $base_attrs, 'em' => $base_attrs, 'span' => $base_attrs, 'ul' => $base_attrs, 'li' => $base_attrs, 'ol' => $base_attrs);
     }
     /**
      * Allow developers to filter what are the allowed HTML on the Excerpt
      *
      * @var array Must be compatible to wp_kses structure
      *
      * @link https://codex.wordpress.org/Function_Reference/wp_kses
      */
     $allowed_html = apply_filters('tribe_events_excerpt_allowed_html', $allowed_html, $post);
     /**
      * Allow shortcodes to be Applied on the Excerpt or not
      *
      * @var bool
      */
     $allow_shortcode = apply_filters('tribe_events_excerpt_allow_shortcode', false);
     // Get the Excerpt or content based on what is available
     if (has_excerpt($post->ID)) {
         $excerpt = $post->post_excerpt;
     } else {
         $excerpt = $post->post_content;
     }
     // Remove all shortcode Content before removing HTML
     if (!$allow_shortcode) {
         $excerpt = preg_replace('#\\[.+\\]#U', '', $excerpt);
     }
     // Remove "all" HTML based on what is allowed
     $excerpt = wp_kses($excerpt, $allowed_html);
     /**
      * Filter the number of words in an excerpt.
      *
      * @param int $number The number of words. Default 55.
      */
     $excerpt_length = apply_filters('excerpt_length', 55);
     /**
      * Filter the string in the "more" link displayed after a trimmed excerpt.
      *
      * @param string $more_string The string shown within the more link.
      */
     $excerpt_more = apply_filters('excerpt_more', ' [&hellip;]');
     // Now we actually trim it
     $excerpt = wp_trim_words($excerpt, $excerpt_length, $excerpt_more);
     return wpautop($excerpt);
 }
 /**
  * Creates a download
  *
  * @since  2.3.6
  * @param  array  $data Array of attributes for a download
  * @return mixed  false if data isn't passed and class not instantiated for creation, or New Download ID
  */
 public function create($data = array())
 {
     if ($this->id != 0) {
         return false;
     }
     $defaults = array('post_type' => 'download', 'post_status' => 'draft', 'post_title' => __('New Download Product', 'easy-digital-downloads'));
     $args = wp_parse_args($data, $defaults);
     do_action('edd_download_pre_create', $args);
     $id = wp_insert_post($args, true);
     $download = WP_Post::get_instance($id);
     do_action('edd_download_post_create', $id, $args);
     return $this->setup_download($download);
 }
 /**
  * Update all taxonomies.
  * This should only ever be called from a cron job scheduled by EasyRecipeScheduler because it can potentially take quite a while
  */
 function updateAll()
 {
     /** @var wpdb $wpdb */
     global $wpdb;
     /**
      * If we are already running, don't do it again
      */
     if ($this->scheduler->isRunning()) {
         return;
     }
     /**
      * Set as running
      * Set a "timeout" of 10 minutes. This will prevent it being re-run for 10 minutes if the current run terminates abnormally for any reason
      */
     $this->scheduler->setRunning(10 * 60);
     $q = "SELECT ID FROM {$wpdb->posts} WHERE post_type NOT IN ('attachment','index','nav_menu_item')";
     $postIDs = $wpdb->get_col($q);
     $this->countTerms['cuisine'] = array();
     $this->countTerms['course'] = array();
     foreach ($postIDs as $postID) {
         $post = WP_Post::get_instance($postID);
         $this->update($post, false);
     }
     /**
      * Update any term counts that we may have adjusted
      */
     if (count($this->countTerms['cuisine']) > 0) {
         wp_update_term_count_now(array_unique(array_keys($this->countTerms['cuisine'])), 'cuisine');
     }
     if (count($this->countTerms['course']) > 0) {
         wp_update_term_count_now(array_unique(array_keys($this->countTerms['course'])), 'course');
     }
     /**
      * Mark the taxonomies as having been created
      */
     $settings = EasyRecipeSettings::getInstance();
     $settings->taxonomiesCreated = true;
     $settings->update();
     /**
      * Mark this job as complete
      */
     $this->scheduler->terminate();
 }
 /**
  * Get things going
  *
  * @since	1.0
  */
 public function __construct($_id = false, $_args = array())
 {
     $form = WP_Post::get_instance($_id);
     return $this->setup_form($form, $_args);
 }
 /**
  * Creates an event
  *
  * @since 	1.3
  * @param 	arr		$data Array of attributes for an event. See $defaults.
  * @return	mixed	false if data isn't passed and class not instantiated for creation, or New Event ID
  */
 public function create($data = array(), $meta = array())
 {
     if ($this->id != 0) {
         return false;
     }
     remove_action('save_post_mdjm-event', 'mdjm_save_event_post', 10, 3);
     $defaults = array('post_type' => 'mdjm-event', 'post_author' => 1, 'post_content' => '', 'post_status' => 'mdjm-enquiry', 'post_title' => __('New Event', 'mobile-dj-manager'));
     $default_meta = array('_mdjm_event_date' => date('Y-m-d'), '_mdjm_event_dj' => !mdjm_get_option('employer') ? 1 : 0, '_mdjm_event_playlist_access' => mdjm_generate_playlist_guest_code(), '_mdjm_event_playlist' => mdjm_get_option('enable_playlists') ? 'Y' : 'N', '_mdjm_event_contract' => mdjm_get_default_event_contract(), '_mdjm_event_cost' => 0, '_mdjm_event_deposit' => 0, '_mdjm_event_deposit_status' => __('Due', 'mobile-dj-manager'), '_mdjm_event_balance_status' => __('Due', 'mobile-dj-manager'), 'mdjm_event_type' => mdjm_get_option('event_type_default'), 'mdjm_enquiry_source' => mdjm_get_option('enquiry_source_default'), '_mdjm_event_venue_id' => 'Manual');
     $data = wp_parse_args($data, $defaults);
     $meta = wp_parse_args($meta, $default_meta);
     do_action('mdjm_event_pre_create', $data, $meta);
     $id = wp_insert_post($data, true);
     $event = WP_Post::get_instance($id);
     if ($event) {
         if (!empty($meta['mdjm_event_type'])) {
             mdjm_set_event_type($event->ID, $meta['mdjm_event_type']);
             $meta['_mdjm_event_name'] = get_term($meta['mdjm_event_type'], 'event-types')->name;
             $meta['_mdjm_event_name'] = apply_filters('mdjm_event_name', $meta['_mdjm_event_name'], $id);
         }
         if (!empty($meta['mdjm_enquiry_source'])) {
             mdjm_set_enquiry_source($event->ID, $meta['mdjm_enquiry_source']);
         }
         if (!empty($meta['_mdjm_event_start']) && !empty($meta['_mdjm_event_finish'])) {
             if (date('H', strtotime($meta['_mdjm_event_finish'])) > date('H', strtotime($meta['_mdjm_event_start']))) {
                 $meta['_mdjm_event_end_date'] = $meta['_mdjm_event_date'];
             } else {
                 $meta['_mdjm_event_end_date'] = date('Y-m-d', strtotime('+1 day', strtotime($meta['_mdjm_event_date'])));
             }
         }
         if (!empty($meta['_mdjm_event_package'])) {
             $meta['_mdjm_event_cost'] += mdjm_get_package_price($meta['_mdjm_event_package'], $meta['_mdjm_event_date']);
         }
         if (!empty($meta['_mdjm_event_addons'])) {
             foreach ($meta['_mdjm_event_addons'] as $addon) {
                 $meta['_mdjm_event_cost'] += mdjm_get_addon_price($addon);
             }
         }
         if (empty($meta['_mdjm_event_deposit'])) {
             $meta['_mdjm_event_deposit'] = mdjm_calculate_deposit($meta['_mdjm_event_cost']);
         }
         mdjm_update_event_meta($event->ID, $meta);
         wp_update_post(array('ID' => $id, 'post_title' => mdjm_get_event_contract_id($id), 'post_name' => mdjm_get_event_contract_id($id)));
     }
     do_action('mdjm_event_post_create', $id, $data);
     add_action('save_post_mdjm-event', 'mdjm_save_event_post', 10, 3);
     return $this->setup_event($event);
 }
Exemple #24
0
 /**
  * Create new Instance of a Post MVI
  *
  * @param WP_Post|int $_post
  * @param array $args {
  *
  *      @type string $instance_class
  *      @type string $list_owner
  *
  *}
  * @return mixed
  *
  * @future Alias this with make_new_post() so it can be called as WPLib::make_new_post( $post_id )
  */
 static function make_new_item($_post, $args = array())
 {
     $args = wp_parse_args($args, array('instance_class' => false, 'list_owner' => 'WPLib_Posts'));
     if (is_numeric($_post)) {
         $_post = WP_Post::get_instance($_post);
     }
     if (!$args['instance_class']) {
         $args['instance_class'] = WPLib::get_constant('INSTANCE_CLASS', $args['list_owner']);
     }
     if (!$args['instance_class']) {
         $args['instance_class'] = self::get_post_type_class($_post->post_type);
     }
     $instance_class = $args['instance_class'];
     return $instance_class ? new $instance_class($_post) : null;
 }
 /**
  * Returns Post Array from ID.
  * Also returns latest post from blog or archive if applicable.
  *
  * @since 2.6.0
  * @since 2.6.6 Added $output parameter.
  *
  * @param int $the_id The Post ID.
  * @param int $tt_id The Taxonomy Term ID
  * @param mixed $output The value type to return. Accepts OBJECT, ARRAY_A, or ARRAY_N
  * @return empty|array The Post Array.
  */
 protected function fetch_post_by_id($the_id = '', $tt_id = '', $output = ARRAY_A)
 {
     if ('' === $the_id && '' === $tt_id) {
         $the_id = $this->get_the_real_ID();
         if (false === $the_id) {
             return '';
         }
     }
     /**
      * @since 2.2.8 Use the 2nd parameter.
      * @since 2.3.3 Now casts to array
      */
     if ('' !== $the_id) {
         if ($this->is_blog_page($the_id)) {
             $args = array('posts_per_page' => 1, 'offset' => 0, 'category' => '', 'category_name' => '', 'orderby' => 'date', 'order' => 'DESC', 'post_type' => 'post', 'post_status' => 'publish', 'cache_results' => false);
             $post = get_posts($args);
         } else {
             $post = get_post($the_id);
         }
     } elseif ('' !== $tt_id) {
         /**
          * @since 2.3.3 Match the descriptions in admin as on the front end.
          */
         $args = array('posts_per_page' => 1, 'offset' => 0, 'category' => $tt_id, 'category_name' => '', 'post_type' => 'post', 'post_status' => 'publish', 'cache_results' => false);
         $post = get_posts($args);
     } else {
         $post = get_post($the_id);
     }
     /**
      * @since 2.6.5 Transform post array to object (on Archives).
      */
     if (is_array($post) && isset($post[0]) && is_object($post[0])) {
         $post = $post[0];
     }
     //* Something went wrong, nothing to be found. Return empty.
     if (empty($post)) {
         return '';
     }
     //* Stop getting something that doesn't exists. E.g. 404
     if (isset($post->ID) && 0 === $post->ID) {
         return '';
     }
     /**
      * @since 2.6.6
      */
     if (ARRAY_A === $output || ARRAY_N === $output) {
         $_post = WP_Post::get_instance($post);
         $post = $_post->to_array();
         if (ARRAY_N === $output) {
             $post = array_values($post);
         }
     }
     return $post;
 }
Exemple #26
0
 /**
  * Returns the parent post this attachment is attached to, if any.
  * @return Attachment|Page|Post|null
  */
 public function parentPost()
 {
     if ($this->parentPost) {
         return $this->parentPost;
     }
     $parent_id = get_post_field('post_parent', $this->id);
     if ($parent_id && !empty($parent_id)) {
         $this->parentPost = $this->context->modelForPost(\WP_Post::get_instance($parent_id));
     }
     return $this->parentPost;
 }
 /**
  * Creates a transaction
  *
  * @since 	1.3
  * @param 	arr		$data Array of attributes for a transaction. See $defaults.
  * @return	mixed	false if data isn't passed and class not instantiated for creation, or New Transaction ID
  */
 public function create($data = array(), $meta = array())
 {
     if ($this->id != 0) {
         return false;
     }
     remove_action('save_post_mdjm-transaction', 'mdjm_save_txn_post', 10, 3);
     $default_data = array('post_type' => 'mdjm-transaction', 'post_status' => 'mdjm-income', 'post_title' => __('New Transaction', 'mobile-dj-manager'), 'post_content' => '');
     $default_meta = array('_mdjm_txn_source' => mdjm_get_option('default_type', __('Cash')), '_mdjm_txn_currency' => mdjm_get_currency(), '_mdjm_txn_status' => 'Pending');
     $data = wp_parse_args($data, $default_data);
     $meta = wp_parse_args($meta, $default_meta);
     do_action('mdjm_pre_txn_create', $data, $meta);
     $id = wp_insert_post($data, true);
     if (is_wp_error($id)) {
         MDJM()->debug->log_it('ERROR: ' . $id->get_error_message());
     }
     $txn = WP_Post::get_instance($id);
     if ($txn) {
         mdjm_update_txn_meta($txn->ID, $meta);
         wp_update_post(array('ID' => $id, 'post_title' => mdjm_get_option('event_prefix') . $id, 'post_name' => mdjm_get_option('event_prefix') . $id));
     }
     do_action('mdjm_post_txn_create', $id, $data, $meta);
     add_action('save_post_mdjm-transaction', 'mdjm_save_txn_post', 10, 3);
     return $this->setup_txn($txn);
 }
 /**
  * Constructor
  *
  * @since 3.8.14
  * @param int|WP_Post $post ID or Post object
  */
 public function __construct($post)
 {
     if (is_object($post)) {
         $this->post = $post;
         return;
     }
     $this->post = WP_Post::get_instance($post);
 }
Exemple #29
0
/**
 * Retrieves post data given a post ID or post object.
 *
 * See {@link sanitize_post()} for optional $filter values. Also, the parameter
 * $post, must be given as a variable, since it is passed by reference.
 *
 * @since 1.5.1
 *
 * @global WP_Post $post
 *
 * @param int|WP_Post|null $post   Optional. Post ID or post object. Defaults to global $post.
 * @param string           $output Optional, default is Object. Accepts OBJECT, ARRAY_A, or ARRAY_N.
 *                                 Default OBJECT.
 * @param string           $filter Optional. Type of filter to apply. Accepts 'raw', 'edit', 'db',
 *                                 or 'display'. Default 'raw'.
 * @return WP_Post|array|null Type corresponding to $output on success or null on failure.
 *                            When $output is OBJECT, a `WP_Post` instance is returned.
 */
function get_post($post = null, $output = OBJECT, $filter = 'raw')
{
    if (empty($post) && isset($GLOBALS['post'])) {
        $post = $GLOBALS['post'];
    }
    if ($post instanceof WP_Post) {
        $_post = $post;
    } elseif (is_object($post)) {
        if (empty($post->filter)) {
            $_post = sanitize_post($post, 'raw');
            $_post = new WP_Post($_post);
        } elseif ('raw' == $post->filter) {
            $_post = new WP_Post($post);
        } else {
            $_post = WP_Post::get_instance($post->ID);
        }
    } else {
        $_post = WP_Post::get_instance($post);
    }
    if (!$_post) {
        return null;
    }
    $_post = $_post->filter($filter);
    if ($output == ARRAY_A) {
        return $_post->to_array();
    } elseif ($output == ARRAY_N) {
        return array_values($_post->to_array());
    }
    return $_post;
}
 /**
  * Creates a download
  *
  * @since  2.3.6
  * @param  array  $data Array of attributes for a download
  * @return mixed  false if data isn't passed and class not instantiated for creation, or New Download ID
  */
 public function create($data = array())
 {
     if ($this->id != 0) {
         return false;
     }
     $defaults = array('post_type' => 'download', 'post_status' => 'draft', 'post_title' => __('New Download Product', 'easy-digital-downloads'));
     $args = wp_parse_args($data, $defaults);
     /**
      * Fired before a download is created
      *
      * @param array $args The post object arguments used for creation.
      */
     do_action('edd_download_pre_create', $args);
     $id = wp_insert_post($args, true);
     $download = WP_Post::get_instance($id);
     /**
      * Fired after a download is created
      *
      * @param int   $id   The post ID of the created item.
      * @param array $args The post object arguments used for creation.
      */
     do_action('edd_download_post_create', $id, $args);
     return $this->setup_download($download);
 }