/** * Set the notification email when sending an email. * * @since WP Job Manager - Contact Listing 1.0.0 * * @return string The email to notify. */ public function notification_email($components, $cf7, $three = null) { $submission = WPCF7_Submission::get_instance(); $unit_tag = $submission->get_meta('unit_tag'); if (!preg_match('/^wpcf7-f(\\d+)-p(\\d+)-o(\\d+)$/', $unit_tag, $matches)) { return $components; } $post_id = (int) $matches[2]; $object = get_post($post_id); // Prevent issues when the form is not submitted via a listing/resume page if (!isset($this->forms[$object->post_type])) { return $components; } if (!array_search($cf7->id(), $this->forms[$object->post_type])) { return $components; } // Bail if this is the second mail if (isset($three) && 'mail_2' == $three->name()) { return $components; } $recipient = $object->_application ? $object->_application : $object->_candidate_email; //if we couldn't find the email by now, get it from the listing owner/author if (empty($recipient)) { //just get the email of the listing author $owner_ID = $object->post_author; //retrieve the owner user data to get the email $owner_info = get_userdata($owner_ID); if (false !== $owner_info) { $recipient = $owner_info->user_email; } } $components['recipient'] = $recipient; return $components; }
public static function get_formated_content() { $post = get_post(); $content = get_the_content(); //Apply "the_content" filter : formats shortcodes etc... : $content = apply_filters('the_content', $content); $content = str_replace(']]>', ']]>', $content); $allowed_tags = '<br/><br><p><div><h1><h2><h3><h4><h5><h6><a><span><sup><sub><img><i><em><strong><b><ul><ol><li><blockquote><pre>'; /** * Filter allowed HTML tags for a given post. * * @param string $allowed_tags A string containing the concatenated list of default allowed HTML tags. * @param WP_Post $post The post object. */ $allowed_tags = apply_filters('wpak_post_content_allowed_tags', $allowed_tags, $post); $content = strip_tags($content, $allowed_tags); /** * Filter a single post content. * * To override (replace) this default formatting completely, use * "wpak_posts_list_post_content" and "wpak_page_content" filters. * * @param string $content The post content. * @param WP_Post $post The post object. */ $content = apply_filters('wpak_post_content_format', $content, $post); return $content; }
function wpcf7_special_mail_tag_for_post_data($output, $name) { if (!isset($_POST['_wpcf7_unit_tag']) || empty($_POST['_wpcf7_unit_tag'])) { return $output; } if (!preg_match('/^wpcf7-f(\\d+)-p(\\d+)-o(\\d+)$/', $_POST['_wpcf7_unit_tag'], $matches)) { return $output; } $post_id = (int) $matches[2]; if (!($post = get_post($post_id))) { return $output; } $user = new WP_User($post->post_author); // For backwards compat. $name = preg_replace('/^wpcf7\\./', '_', $name); if ('_post_id' == $name) { $output = (string) $post->ID; } elseif ('_post_name' == $name) { $output = $post->post_name; } elseif ('_post_title' == $name) { $output = $post->post_title; } elseif ('_post_url' == $name) { $output = get_permalink($post->ID); } elseif ('_post_author' == $name) { $output = $user->display_name; } elseif ('_post_author_email' == $name) { $output = $user->user_email; } return $output; }
/** * Prevent caching on dynamic pages. * * @access public * @return void */ public function init() { if (false === ($wc_page_uris = get_transient('woocommerce_cache_excluded_uris'))) { if (woocommerce_get_page_id('cart') < 1 || woocommerce_get_page_id('checkout') < 1 || woocommerce_get_page_id('myaccount') < 1) { return; } $wc_page_uris = array(); $cart_page = get_post(woocommerce_get_page_id('cart')); $checkout_page = get_post(woocommerce_get_page_id('checkout')); $account_page = get_post(woocommerce_get_page_id('myaccount')); $wc_page_uris[] = '/' . $cart_page->post_name; $wc_page_uris[] = '/' . $checkout_page->post_name; $wc_page_uris[] = '/' . $account_page->post_name; $wc_page_uris[] = 'p=' . $cart_page->ID; $wc_page_uris[] = 'p=' . $checkout_page->ID; $wc_page_uris[] = 'p=' . $account_page->ID; set_transient('woocommerce_cache_excluded_uris', $wc_page_uris); } if (is_array($wc_page_uris)) { foreach ($wc_page_uris as $uri) { if (strstr($_SERVER['REQUEST_URI'], $uri)) { $this->nocache(); break; } } } }
/** * Create new fields for variations * */ function variable_fields($loop, $variation_data, $variation) { global $post; if (!$post) { $post = get_post($variation->ID); } ?> <tr> <td> </br> <?php //$_pg_field = $variation_data['_pg_field'][0] $variation_id = $variation->ID; $_pg_field = get_post_meta($variation_id, '_pg_field', true); /* echo "</br>"; var_dump($variation_data); echo "</br>"; echo "</br>"; var_dump($variation); echo "</br>"; echo "</br>"; var_dump($_pg_field); echo "</br>"; echo "</br>"."_pg_field : ". $_pg_field ."</br>"; echo "</br>"; */ woocommerce_wp_text_input(array('id' => '_pg_field[' . $loop . ']', 'label' => __('Product Generator Data', 'woocommerce'), 'placeholder' => 'angle="33" lux="100" luxD="100" minD="100" maxD="500"', 'desc_tip' => 'true', 'description' => __('Enter the Product Generator Data here.', 'woocommerce'), 'value' => $_pg_field)); ?> </td> </tr> <?php }
/** * Display navigation to next/previous post when applicable. * * @since DSW oddil 1.0 */ function dswoddil_post_nav() { // Don't print empty markup if there's nowhere to navigate. $previous = is_attachment() ? get_post(get_post()->post_parent) : get_adjacent_post(false, '', true); $next = get_adjacent_post(false, '', false); if (!$next && !$previous) { return; } ?> <nav class="navigation post-navigation" role="navigation"> <h1 class="screen-reader-text"><?php _e('Post navigation', 'dswoddil'); ?> </h1> <div class="nav-links"> <?php if (is_attachment()) { previous_post_link('%link', __('<span class="meta-nav">Published In</span>%title', 'dswoddil')); } else { previous_post_link('%link', __('<span class="meta-nav">Previous Post</span>%title', 'dswoddil')); next_post_link('%link', __('<span class="meta-nav">Next Post</span>%title', 'dswoddil')); } ?> </div><!-- .nav-links --> </nav><!-- .navigation --> <?php }
public function getImage($id) { $image_fields = array("ID" => "ID", "guid" => "file", "post_mime_type" => "mime_type"); $indexable_image_size = get_intermediate_image_sizes(); $uploadDir = wp_upload_dir(); $uploadBaseUrl = $uploadDir['baseurl']; $image = new \stdClass(); $post = get_post($id); foreach ($image_fields as $key => $value) { $image->{$value} = $post->{$key}; } $metas = get_post_meta($post->ID, '_wp_attachment_metadata', true); $image->width = $metas["width"]; $image->height = $metas["height"]; $image->file = sprintf('%s/%s', $uploadBaseUrl, $metas["file"]); $image->sizes = $metas["sizes"] ? $metas["sizes"] : array(); foreach ($image->sizes as $size => &$sizeAttrs) { if (in_array($size, $indexable_image_size) == false) { unset($image->sizes[$size]); continue; } $baseFileUrl = str_replace(wp_basename($metas['file']), '', $metas['file']); $sizeAttrs['file'] = sprintf('%s/%s%s', $uploadBaseUrl, $baseFileUrl, $sizeAttrs['file']); } return $image; }
/** * Display navigation to next/previous post when applicable. * * @return void */ function my_simone_post_nav() { // Don't print empty markup if there's nowhere to navigate. $previous = is_attachment() ? get_post(get_post()->post_parent) : get_adjacent_post(false, '', true); $next = get_adjacent_post(false, '', false); if (!$next && !$previous) { return; } ?> <nav class="navigation post-navigation" role="navigation"> <div class="post-nav-box clear"> <h1 class="screen-reader-text"><?php _e('Post navigation', 'my-simone'); ?> </h1> <div class="nav-links"> <?php previous_post_link('<div class="nav-previous"><div class="nav-indicator">' . _x('Previous Post:', 'Previous post', 'my-simone') . '</div><h1>%link</h1></div>', '%title'); next_post_link('<div class="nav-next"><div class="nav-indicator">' . _x('Next Post:', 'Next post', 'my-simone') . '</div><h1>%link</h1></div>', '%title'); ?> </div><!-- .nav-links --> </div><!-- .post-nav-box --> </nav><!-- .navigation --> <?php }
function test_ajax() { header("content-type: applications/json"); $posts_array = get_post(); echo json_encode($posts_array); die; }
function __construct($item_id) { $my_post = get_post($item_id); $this->id = $item_id; $this->title = $my_post->post_title; $this->price = get_post_meta($item_id, 'item_price', TRUE); }
/** * Render Wish List Columns * * @since 1.0 * @param string $column_name Column name * @param int $post_id Download (Post) ID * @return void */ function edd_wl_render_admin_columns($column_name, $post_id) { if (get_post_type($post_id) == 'edd_wish_list') { $items = get_post_meta(get_the_ID(), 'edd_wish_list', true); switch ($column_name) { case 'downloads': if ($items) { echo count($items); } else { echo 0; } break; case 'total': echo edd_wl_get_list_total(get_the_ID()); break; case 'list_author': $post = get_post(); if (0 == $post->post_author) { echo __('Guest', 'edd-wish-lists'); } else { printf('<a href="%s">%s</a>', esc_url(add_query_arg(array('post_type' => $post->post_type, 'author' => get_the_author_meta('ID')), 'edit.php')), get_the_author()); } break; } } }
/** * How to display the widget on the screen. */ function widget($args, $instance) { global $wp_query; $this_id = $wp_query->post->ID; $post = get_post($this_id); $this_type = $wp_query->post->post_type; if ($this_type == 'landing-page') { extract($args); $position = $_SESSION['lp_conversion_area_position']; if ($position == 'widget') { $title = apply_filters('widget_title', $instance['title']); /* Before widget (defined by themes). */ echo $before_widget; /* Display the widget title if one was input (before and after defined by themes). */ if ($title) { echo $before_title . $title . $after_title; } echo "<div id='lp_container' class='inbound-conversion-sidebar'>"; echo do_shortcode(lp_conversion_area($post, $content = null, $return = true, $doshortcode = false)); echo "</div>"; /* After widget (defined by themes). */ echo $after_widget; } } }
static function get_posts($args = array(), $current = 0) { $deff = array('post_type' => 'page', 'posts_per_page' => 40, 'post_status' => 'publish'); if (empty($args)) { $args = $deff; } else { if (!isset($args['post_type'])) { $args['post_type'] = $deff['post_type']; } if (!isset($args['posts_per_page'])) { $args['posts_per_page'] = $deff['posts_per_page']; } if (!isset($args['post_status'])) { $args['post_status'] = $deff['post_status']; } } $query = new WP_Query($args); $rett = array(0 => __(' - Select from list - ', 'materialize')); if (count($query->posts)) { foreach ($query->posts as $p) { $rett[$p->ID] = esc_attr(get_the_title($p->ID)); } } if (absint($current) > 0 && !isset($rett[$current])) { $p_ = get_post($current); if (isset($p_->ID)) { $rett[$p_->ID] = esc_attr(get_the_title($p_->ID)); } } return $rett; }
function excerpt($excerpt = '', $length = '') { // Save a copy of the raw excerpt $raw_excerpt = $excerpt; // Excerpt length default if (empty($length)) { $length = absint(option('excerpt_length')); } // Generate an excerpt where none exists if (empty($excerpt)) { $post = get_post(); if (empty($post)) { return; } // Don't return an excerpt for a protected post if (post_password_required($post->ID)) { return esc_html__('This post is protected.', 'ubik'); } // Post contents will serve as the basis for generating the excerpt $excerpt = $post->post_content; } // Sanitize excerpt $excerpt = apply_filters('ubik_excerpt_sanitize', wptexturize(\Ubik\text_truncate($excerpt, $length, esc_html(option('excerpt_more'))))); // Run the excerpt through a filter on the way out the door return apply_filters('ubik_excerpt', $excerpt, $raw_excerpt); }
/** * Display navigation to next/previous post when applicable. */ function zerif_post_nav() { // Don't print empty markup if there's nowhere to navigate. $previous = is_attachment() ? get_post(get_post()->post_parent) : get_adjacent_post(false, '', true); $next = get_adjacent_post(false, '', false); if (!$next && !$previous) { return; } ?> <nav class="navigation post-navigation"> <h2 class="screen-reader-text"><?php _e('Post navigation', 'zerif-lite'); ?> </h2> <div class="nav-links"> <?php previous_post_link('<div class="nav-previous">%link</div>', _x('<span class="meta-nav">←</span> %title', 'Previous post link', 'zerif-lite')); next_post_link('<div class="nav-next">%link</div>', _x('%title <span class="meta-nav">→</span>', 'Next post link', 'zerif-lite')); ?> </div><!-- .nav-links --> </nav><!-- .navigation --> <?php }
public function __construct($bean = null) { $post = null; $this->capabilityType = 'post'; $this->serializeDataStorage = true; // If your class name is Book. Your Post Type would be 'book' $this->getPostType(); if (is_int($bean)) { $post = get_post($bean); } elseif ($bean instanceof \WP_Post && !empty($bean->ID)) { $post = $bean; } // Load Basic post data if (!empty($post)) { $this->post = $post; $this->ID = $post->ID; $this->title = $post->post_title; $this->content = $post->post_content; $this->excerpt = $post->post_excerpt; } // Setup Basic post data if (empty($this->nameLabel)) { $currentObjectName = $this->getClassName(); $this->setNameLabel($currentObjectName); $this->setSingularNameLabel($currentObjectName); } //Metaboxes and Fields $this->metaBoxes = new MetaBoxCollection(); $this->fields = new FieldCollection(); $this->tableFields = array(); $this->registerCustomPostType()->registerFilters(); }
/** * get_order function. * * @param bool $the_order (default: false) * @return WC_Order|bool */ public function get_order($the_order = false) { global $post; if (false === $the_order) { $the_order = $post; } elseif (is_numeric($the_order)) { $the_order = get_post($the_order); } if (!$the_order || !is_object($the_order)) { return false; } $order_id = absint($the_order->ID); $post_type = $the_order->post_type; if ($order_type = wc_get_order_type($post_type)) { $classname = $order_type['class_name']; } else { $classname = false; } // Filter classname so that the class can be overridden if extended. $classname = apply_filters('woocommerce_order_class', $classname, $post_type, $order_id); if (!class_exists($classname)) { $classname = 'WC_Order'; } return new $classname($the_order); }
function start_el(&$output, $page, $depth = 0, $args = array(), $current_page = 0) { if ($depth) { $indent = str_repeat("\t", $depth); } else { $indent = ''; } extract($args, EXTR_SKIP); $css_class = array('page_item', 'page-item-' . $page->ID); if (!empty($current_page)) { $_current_page = get_post($current_page); if (in_array($page->ID, $_current_page->ancestors)) { $css_class[] = 'current_page_ancestor'; } if ($page->ID == $current_page) { $css_class[] = 'current_page_item'; } elseif ($_current_page && $page->ID == $_current_page->post_parent) { $css_class[] = 'current_page_parent'; } } elseif ($page->ID == get_option('page_for_posts')) { $css_class[] = 'current_page_parent'; } $css_class = implode(' ', apply_filters('page_css_class', $css_class, $page, $depth, $args, $current_page)); $output .= $indent . '<li class="' . $css_class . '"><a href="' . get_permalink($page->ID) . '">' . $link_before . apply_filters('the_title', $page->post_title, $page->ID) . $link_after . '</a>'; if (!empty($show_date)) { if ('modified' == $show_date) { $time = $page->post_modified; } else { $time = $page->post_date; } $output .= " " . mysql2date($date_format, $time); } }
/** * Test autosaving a post * @return void */ public function test_autosave_post() { // Become an admin $this->_setRole( 'administrator' ); // Set up the $_POST request $md5 = md5( uniqid() ); $_POST = array( 'post_id' => $this->_post->ID, 'autosavenonce' => wp_create_nonce( 'autosave' ), 'post_content' => $this->_post->post_content . PHP_EOL . $md5, 'post_type' => 'post', 'autosave' => 1, ); // Make the request try { $this->_handleAjax( 'autosave' ); } catch ( WPAjaxDieContinueException $e ) { unset( $e ); } // Get the response $xml = simplexml_load_string( $this->_last_response, 'SimpleXMLElement', LIBXML_NOCDATA ); // Ensure everything is correct $this->assertEquals( $this->_post->ID, (int) $xml->response[0]->autosave['id'] ); $this->assertEquals( 'autosave_' . $this->_post->ID, (string) $xml->response['action']); // Check that the edit happened $post = get_post( $this->_post->ID) ; $this->assertGreaterThanOrEqual( 0, strpos( $post->post_content, $md5 ) ); }
/** * Enqueue the admin script to page post types only * * @uses get_post() * @uses wp_enqueue_script() * * @return void */ function admin_enqueue_scripts() { $post = get_post(); if ($post && 'page' === $post->post_type) { wp_enqueue_script('city-admin', TMP_CITIES_URL . 'assets/js/template-cities.js', array(), TMP_CITIES_VERSION, true); } }
function base_fancybox_gallery_shortcode($atts, $content = null) { $parameters = shortcode_atts(array('small' => '', 'medium' => '', 'large' => '', 'class' => '', 'identifier' => '', 'ids' => ''), $atts, 'fancy_gallery'); $return_html = ''; $return_html .= '<ul class="'; $return_html .= $parameters['small'] != '' ? 'small-block-grid-' . $parameters['small'] . ' ' : ''; $return_html .= $parameters['medium'] != '' ? 'medium-block-grid-' . $parameters['medium'] . ' ' : ''; $return_html .= $parameters['large'] != '' ? 'large-block-grid-' . $parameters['large'] . ' ' : ''; $return_html .= $parameters['class'] != '' ? $parameters['class'] : ''; $return_html .= '">'; $id_list = explode(",", $parameters['ids']); foreach ($id_list as $id) { $item = get_post($id); $title = $item->post_title; $caption = $item->post_excerpt; $description = $item->post_content; $url = $item->guid; $return_html .= '<li>'; $return_html .= '<a href="' . $url . '" class="fancybox" '; $return_html .= 'rel="' . $parameters['identifier'] . '" '; $return_html .= 'title="' . $title . '">'; //$return_html .= 'style="background-image:url('.$url.');">'; $return_html .= '<img src="' . $url . '" />'; $return_html .= '</a>'; $return_html .= '</li>'; } $return_html .= '</ul>'; return $return_html; }
function __construct($id = '', $status = 'any', $output = 'OBJECT') { $continue = true; if ($status !== 'any') { if (get_post_status($id) == $status) { $continue = true; } else { $continue = false; } } if ($continue) { $this->id = $id; $this->output = $output; $this->details = get_post($this->id, $this->output); $tickets = new TC_Tickets(); $fields = $tickets->get_ticket_fields(); if (isset($this->details)) { if (!empty($fields)) { foreach ($fields as $field) { if (!isset($this->details->{$field['field_name']})) { $this->details->{$field['field_name']} = get_post_meta($this->id, $field['field_name'], true); } } } } } else { $this->id = null; } }
function ultimatum_meta_save_postdata( $post_id, $post ) { //echo '<pre>';print_r($_POST);die(); //* Verify the nonce if ( ! isset( $_POST[ 'ultimatum_additional_meta_nonce' ] ) || ! wp_verify_nonce( $_POST[ 'ultimatum_additional_meta_nonce' ], 'ultimatum_additional_meta' ) ) return; //* Don't try to save the data under autosave, ajax, or future post. if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return; if ( defined( 'DOING_AJAX' ) && DOING_AJAX ) return; if ( defined( 'DOING_CRON' ) && DOING_CRON ) return; //* Grab the post object $post = get_post( $post ); //* Don't save if WP is creating a revision (same as DOING_AUTOSAVE?) if ( 'revision' === $post->post_type ) return; //* Check that the user is allowed to edit the post if ( ! current_user_can( 'edit_post', $post->ID ) ) return; $mydata = $_POST['ultimatum_video']; update_post_meta($post->ID, 'ultimatum_video', $mydata); $mydata = $_POST['ultimatum_author']; update_post_meta($post->ID, 'ultimatum_author', $mydata); }
public function __construct(Episode $episode) { $this->episode = $episode; $this->post = get_post($episode->post_id); $this->player_format_assignments = $this->get_player_format_assignments(); $this->files = $this->get_files(); }
public function __construct($post = null) { $this->initial = true; $this->form = ''; $this->mail = array(); $this->mail_2 = array(); $this->messages = array(); $this->additional_settings = ''; $post = get_post($post); if ($post && self::post_type == get_post_type($post)) { $this->initial = false; $this->id = $post->ID; $this->title = $post->post_title; $props = $this->get_properties(); foreach ($props as $prop => $value) { if (metadata_exists('post', $post->ID, '_' . $prop)) { $this->{$prop} = get_post_meta($post->ID, '_' . $prop, true); } else { $this->{$prop} = get_post_meta($post->ID, $prop, true); } } $this->upgrade(); } do_action_ref_array('wpcf7_contact_form', array(&$this)); }
/** * widget function. * * @see WP_Widget * @access public * @param array $args * @param array $instance * @return void */ function widget($args, $instance) { if ($this->get_cached_widget($args)) { return; } global $job_manager, $post; extract($args); $title = apply_filters('widget_title', $instance['title'], $instance, $this->id_base); $icon = isset($instance['icon']) ? $instance['icon'] : null; $gallery = Listify_WP_Job_Manager_Gallery::get(get_post()->ID); $limit = isset($instance['limit']) ? $instance['limit'] : 8; $has_more = count($gallery) > $limit; if (empty($gallery) && !current_user_can('upload_files')) { return; } if ($icon) { $before_title = sprintf($before_title, 'ion-' . $icon); } ob_start(); if ($has_more) { $before_widget = str_replace('widget-job_listing', 'widget-job_listing has-more', $before_widget); } echo $before_widget; if ($title) { echo $before_title . sprintf('<a href="%s" class="image-gallery-link">%s</a>', Listify_WP_Job_Manager_Gallery::url(), $title) . $after_title; } include locate_template(array('content-single-job_listing-gallery-overview.php')); if ($has_more) { printf('<a href="%s" class="go-to-gallery"><i class="ion-ios7-more"></i></a>', Listify_WP_Job_Manager_Gallery::url()); } echo $after_widget; $content = ob_get_clean(); echo apply_filters($this->widget_id, $content); $this->cache_widget($args, $content); }
function html_sitemap_shortcode_handler($args, $content = null) { if (is_feed()) { return ''; } $args['echo'] = 0; $args['title_li'] = ''; unset($args['link_before']); unset($args['link_after']); if (isset($args['child_of']) && $args['child_of'] == 'CURRENT') { $args['child_of'] = get_the_ID(); } else { if (isset($args['child_of']) && $args['child_of'] == 'PARENT') { $post =& get_post(get_the_ID()); if ($post->post_parent) { $args['child_of'] = $post->post_parent; } else { unset($args['child_of']); } } } $html = wp_list_pages($args); // Remove the classes added by WordPress $html = preg_replace('/( class="[^"]+")/is', '', $html); return '<ul>' . $html . '</ul>'; }
public function on_edit() { if (isset($_POST['submit'])) { //输入 $nickname = get_post('nickname'); $email = get_post('email'); $sex = get_post('sex'); $birthday = get_post('birthday'); // $mobile = get_post('mobile'); //检查输入 if (!$this->user_id || !$nickname || !$email || !$sex) { // if (!$this->user_id || !$nickname || !$email || !$sex || !$mobile) { $this->error_message('参数不能为空'); } //入库 //少了卡号,生日 $data = array('email' => $email, 'nickname' => $nickname, 'sex' => $sex); $result = $this->db->where('user_id', $this->user_id)->update('user', $data); if ($result === false) { $this->error_message('修改出错,请联系管理人员'); } $this->success_message('修改成功'); return true; } $user_row = $this->db->where('user_id', $this->user_id)->row('user'); foreach ($user_row as $key => $value) { $this->view->assign($key, $value); } $this->view->display('user/edit.html', $user_row); }
/** * Gets the specified media and meta info from the given post. * NOTE: If you have the post's HTML content already and don't need image data, use extract_from_content() instead. * * @param $blog_id The ID of the blog * @param $post_id The ID of the post * @param $what_to_extract (int) A mask of things to extract, e.g. Jetpack_Media_Meta_Extractor::IMAGES | Jetpack_Media_Meta_Extractor::MENTIONS * @returns a structure containing metadata about the embedded things, or empty array if nothing found, or WP_Error on error */ public static function extract($blog_id, $post_id, $what_to_extract = self::ALL) { // multisite? if (function_exists('switch_to_blog')) { switch_to_blog($blog_id); } $post = get_post($post_id); $content = $post->post_title . "\n\n" . $post->post_content; $char_cnt = strlen($content); //prevent running extraction on really huge amounts of content if ($char_cnt > 100000) { //about 20k English words $content = substr($content, 0, 100000); } $extracted = array(); // Get images first, we need the full post for that if (self::IMAGES & $what_to_extract) { $extracted = self::get_image_fields($post); // Turn off images so we can safely call extract_from_content() below $what_to_extract = $what_to_extract - self::IMAGES; } if (function_exists('switch_to_blog')) { restore_current_blog(); } // All of the other things besides images can be extracted from just the content $extracted = self::extract_from_content($content, $what_to_extract, $extracted); return $extracted; }
function the_excerpt_max_charlength_page($postid, $charlength) { $my_postid = $postid; //This is page id or post id $content_post = get_post($my_postid); $excerpt = $content_post->post_content; $excerpt = apply_filters('the_content', $excerpt); $excerpt = str_replace(']]>', ']]>', $excerpt); //$excerpt = get_field('descripcion', $postid); $charlength++; $return = ""; if (mb_strlen($excerpt) > $charlength) { $subex = mb_substr($excerpt, 0, $charlength - 5); $exwords = explode(' ', $subex); $excut = -mb_strlen($exwords[count($exwords) - 1]); if ($excut < 0) { $return .= mb_substr($subex, 0, $excut); } else { $return .= $subex; } $return .= '[...]'; } else { $return .= $excerpt; } return $return; }