Exemplo n.º 1
0
/**
 * Render example of Edit Post screen meta box, based on settings using post's meta box fn.
 *
 * @since   0.3.0
 * @see   /includes/meta-box.php
 * @uses  postscript_get_options()  Safely gets site option
 */
function postscript_meta_box_example()
{
    $options = postscript_get_options('postscript');
    $box['args'] = $options;
    // Meta box stores $options as an ['args'] array.
    $fake_post = (object) array('ID' => '-1');
    // Meta box needs a post object id.
    ?>
    <hr />
    <h2 id="metabox"><?php 
    _e('Postscript meta box example', 'postscript');
    ?>
</h2>
    <p>
        <?php 
    _e('This meta box displays on the Edit Post screen:', 'postscript');
    ?>
<br />
        <?php 
    _e('&bull; For user-role(s): ', 'postscript');
    echo implode($options['user_roles'], ', ');
    ?>
<br />
        <?php 
    _e('&bull; For post-type(s): ', 'postscript');
    echo implode($options['post_types'], ', ');
    ?>
    <p>

    <div id="postscript-meta" class="postbox-container">
        <div id="categorydiv" class="postbox ">
        <h2 class="hndle ui-sortable-handle"><span>Postscript</span></h2>
            <div class="inside">
                <?php 
    postscript_meta_box_callback($fake_post, $box);
    ?>
            </div><!-- .inside -->
        </div><!-- .postbox -->
    </div><!-- .postbox-container -->

    <p class="clear wp-ui-text-icon">The top-right <a href="#contextual-help-link">Help tab</a> has details on Postscript features. <?php 
    _e('This plugin created as part of a <a href="https://www.rjionline.org/stories/series/storytelling-tools/">Reynold Journalism Institute</a> fellowship.', 'mexpplus');
    ?>
</p>
    <p class="clear wp-ui-text-icon"><small>(<?php 
    echo get_num_queries();
    _e(" queries in ", 'postscript');
    timer_stop(1);
    _e(" seconds uses ", 'postscript');
    echo size_format(memory_get_peak_usage(), 2);
    ?>
 <?php 
    _e(" peak memory", 'postscript');
    ?>
.)</small>
    <?php 
}
Exemplo n.º 2
0
/**
 * Checks enqueued URL hostname against whitelist.
 *
 * @since   0.4.0
 *
 * @param  string   $url    URL to be checked.
 * @return bool             True if extension is in whitelist, false if not.
 */
function postscript_check_url_hostname($url)
{
    $options = postscript_get_options();
    $hostname = parse_url($url, PHP_URL_HOST);
    $hostname_whitelist = explode(',', $options['url_whitelist']);
    if (in_array($hostname, $hostname_whitelist)) {
        return true;
    }
    return false;
}
Exemplo n.º 3
0
/**
 * Sets default settings option upon activation, if options doesn't exist.
 *
 * @uses postscript_get_options()   Safely get site option, check plugin version.
 */
function postscript_activate()
{
    postscript_get_options();
}
Exemplo n.º 4
0
/**
 * Creates meta box for the post editor screen.
 *
 * Passes array of user-setting options to callback.
 *
 * @uses postscript_get_options()   Safely gets option from database.
 */
function postscript_add_meta_box()
{
    $options = postscript_get_options();
    add_meta_box('postscript-meta', esc_html__('Postscript', 'postscript'), 'postscript_meta_box_callback', $options['post_types'], 'side', 'default', $options);
}
Exemplo n.º 5
0
/**
 * Adds user-entered class(es) to the post class list.
 *
 * @uses postscript_get_options()   Safely gets option from database.
 * @return  array $classes  WordPress defaults and user-added classes
 */
function postscript_class_post($classes)
{
    $post_id = get_the_ID();
    $options = postscript_get_options();
    if (!empty($post_id) && isset($options['allow']['class_post'])) {
        // Get the custom post class.
        $postscript_meta = get_post_meta($post_id, 'postscript_meta', true);
        // If a post class was input, sanitize it and add it to the post class array.
        if (!empty($postscript_meta['class_post'])) {
            $classes[] = sanitize_html_class($postscript_meta['class_post']);
        }
    }
    return $classes;
}