/** * Save images via AJAX 'images' metabox type. * * @return void */ function stag_save_images() { if (defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) { return; } if (!isset($_POST['ids']) || !isset($_POST['nonce']) || !wp_verify_nonce($_POST['nonce'], 'stag-ajax')) { return; } if (!current_user_can('edit_posts')) { return; } $ids = strip_tags(rtrim($_POST['ids'], ',')); stag_update_post_meta('settings', $_POST['post_id'], 'stag_image_ids', $ids); $thumbs = explode(',', $ids); $thumbs_output = ''; foreach ($thumbs as $thumb) { $thumbs_output .= '<li>' . wp_get_attachment_image($thumb, array(75, 75)) . '</li>'; } echo $thumbs_output; die; }
/** * Calculate post reading time. * * Cache the post reading time under post meta for better performance. * * @uses stag_get_post_meta() * @uses stag_update_post_meta() * @since 1.0.0. * @param int $post_id Post ID of which to calculate the post reading time. * @return mixed */ function stag_post_reading_time($post_id = null) { if (0 === absint($post_id)) { $post_id = get_the_ID(); } // Use cached value if available $char_count = stag_get_post_meta('cache', $post_id, 'char-count'); if (false !== $char_count) { $char_count = absint($char_count); } else { $content = wp_strip_all_tags(strip_shortcodes(get_post($post_id)->post_content), true); /** * Use - count( preg_split( '/\s+/', $content ) ) * for compatibility with cyrillic or other characters which are not assumed words. * * @since 1.1.0 */ $char_count = apply_filters('post_words_count', str_word_count($content)); // Cache the value stag_update_post_meta('cache', $post_id, 'char-count', $char_count); } $wpm = apply_filters('ink_words_per_minute', 200); // Get Estimated time $minutes = floor($char_count / $wpm); $seconds = floor($char_count / ($wpm / 60) - $minutes * 60); // If less than a minute if ($minutes < 1) { $estimated_time = __('1 minuto', 'stag'); } // If more than a minute if ($minutes > 1) { if ($seconds > 30) { $minutes++; } /* translators: %d = minute count */ $estimated_time = sprintf(__('%d minutos', 'stag'), $minutes); } return $estimated_time; }