예제 #1
0
/**
 * Returns a dynamic list of posts based on the supplied post_type.
 *
 * @since 1.1-beta-2
 *
 * @param array|null $atts The attributes this output depends on.
 * @return array The new options list
 */
function render_sc_populate_post_type($atts)
{
    $options = render_sc_post_list(array('post_type' => isset($atts['post_type']) ? $atts['post_type'] : 'any', 'public' => true));
    return array('options' => render_build_options_html($options), 'no_options_text' => __('No posts available.', 'Render'));
}
예제 #2
0
/**
 * Populates the parameter selectbox conditionally for the logic shortcode.
 *
 * @since  1.1-beta-2
 * @access private
 * @param array $atts The dependent attributes.
 * @return array The selectbox options.
 */
function _render_sc_logic_param_populate($atts)
{
    $response = array('options' => array(), 'no_options_text' => false, 'description' => false);
    switch ($atts['arg1']) {
        case 'single':
            $response['options'] = render_sc_post_list(array('post_type' => 'post'));
            $response['no_options_text'] = __('No posts available.', 'Render');
            $response['description'] = __('Leave blank to just check if this is any post.', 'Render');
            break;
        case 'page':
            $response['options'] = render_sc_post_list(array('post_type' => 'page'));
            $response['no_options_text'] = __('No pages available.', 'Render');
            $response['description'] = __('Leave blank to just check if this is any page.', 'Render');
            break;
        case 'category':
            $response['options'] = render_sc_term_list(array('taxonomies' => array('category')));
            $response['no_options_text'] = __('No categories available.', 'Render');
            $response['description'] = __('Leave blank to just check if this is any category page.', 'Render');
            break;
        case 'tag':
            $response['options'] = render_sc_term_list(array('taxonomies' => array('post_tag')));
            $response['no_options_text'] = __('No tags available.', 'Render');
            $response['description'] = __('Leave blank to just check if this is any tag page.', 'Render');
            break;
        case 'tax':
            $response['options'] = render_sc_term_list();
            $response['no_options_text'] = __('No taxonomies available.', 'Render');
            $response['description'] = __('Leave blank to just check if this is any taxonomy page.', 'Render');
            break;
        case 'author':
            $response['options'] = render_sc_user_list('edit_posts');
            $response['no_options_text'] = __('No authors available.', 'Render');
            $response['description'] = __('Leave blank to just check if this is any author archive.', 'Render');
            break;
    }
    // Convert the options to HTML
    $response['options'] = !empty($response['options']) ? render_build_options_html($response['options']) : '';
    return $response;
}
예제 #3
0
/**
 * Outputs an attribute template.
 *
 * @since 1.0.0
 *
 * @param string $template Which template to use.
 * @param array  $extra    Extra attribute parameters to use (or override).
 * @param array  $args     Optional args that some cases use.
 * @return array Attribute.
 */
function render_sc_attr_template($template, $extra = array(), $args = array())
{
    global $post;
    $output = array();
    // Set the timezone accordingly for displaying the output
    $orig_timezone = date_default_timezone_get();
    $timezone = get_option('timezone_string', 'UTC');
    date_default_timezone_set(!empty($timezone) ? $timezone : 'UTC');
    switch ($template) {
        case 'date_format':
            $output = array('label' => __('Date Format', 'Render'), 'type' => 'selectbox', 'description' => sprintf(__('Format to display the date. Either choose one or input a custom date format using %s date format standards.', 'Render'), '<a href="http://php.net/manual/en/function.date.php" target="_blank">PHP</a>'), 'properties' => array('placeholder' => __('Select a date format or enter a custom format.', 'Render'), 'default' => 'default_date', 'allowCustomInput' => true, 'options' => array('default_date' => __('Date format set in Settings -> General', 'Render'), 'l, F jS, Y - g:iA' => date('l, F jS, Y - g:iA'), 'l, F jS, Y' => date('l, F jS, Y'), 'F jS, Y' => date('F jS, Y'), 'M jS, Y' => date('M jS, Y'), 'm-d-Y' => date('m-d-Y'), 'd-m-Y' => date('d-m-Y'), 'm-d-y' => date('m-d-y'), 'd-m-y' => date('d-m-y'), 'j-n-y' => date('j-n-y'), 'n-j-y' => date('n-j-y'))));
            break;
        case 'full_date_format':
            $output = array('label' => __('Format', 'Render'), 'type' => 'selectbox', 'description' => sprintf(__('Format to display the date. Either choose one or input a custom date format using %s date format standards.', 'Render'), '<a href="http://php.net/manual/en/function.date.php" target="_blank">PHP</a>'), 'properties' => array('placeholder' => __('Select a date format or enter a custom format.', 'Render'), 'default' => 'default_date', 'allowCustomInput' => true, 'groups' => array(array('label' => __('Full Date', 'Render'), 'options' => array('default_date' => __('Date format set in Settings -> General', 'Render'), 'l, F jS, Y - g:iA' => date('l, F jS, Y - g:iA'), 'l, F jS, Y' => date('l, F jS, Y'), 'F jS, Y' => date('F jS, Y'), 'M jS, Y' => date('M jS, Y'), 'm-d-Y' => date('m-d-Y'), 'd-m-Y' => date('d-m-Y'), 'm-d-y' => date('m-d-y'), 'd-m-y' => date('d-m-y'), 'j-n-y' => date('j-n-y'), 'n-j-y' => date('n-j-y'))), array('label' => __('Day', 'Render'), 'options' => array('l' => date('l'), 'D' => date('D'), 'jS' => date('jS'), 'd' => date('d'), 'j' => date('j'))), array('label' => __('Week of Year', 'Render'), 'options' => array('W' => date('W'))), array('label' => __('Month', 'Render'), 'options' => array('F' => date('F'), 'M' => date('M'), 'm' => date('m'), 'n' => date('n'))), array('label' => __('Year', 'Render'), 'options' => array('Y' => date('Y'), 'y' => date('y'))), array('label' => __('Time', 'Render'), 'options' => array('default_time' => __('Time format set in Settings -> General', 'Render'), 'g:i A' => date('g:i A'), 'g:i a' => date('g:i a'), 'h:i A' => date('h:i A'), 'h:i a' => date('h:i a'), 'H:i' => date('H:i'))))));
            break;
        case 'post_list':
            // Get our default properties set up
            $properties = array('placeholder' => __('The current post', 'Render'), 'no_options' => __('No posts available.', 'Render'));
            // Get our options or groups and then set the appropriate one by determining the array depth
            foreach ($options = render_sc_post_list($args) as $group => $_options) {
                $properties[is_array($_options) ? 'groups' : 'options'] = $options;
                break;
            }
            $output = array('label' => __('Post', 'Render'), 'type' => 'selectbox', 'default' => is_object($post) ? $post->ID : null, 'properties' => $properties);
            break;
        case 'post_type_list':
            $output = array('label' => __('Post Type', 'Render'), 'type' => 'selectbox', 'default' => 'any', 'properties' => array('allowDeselect' => false, 'options' => array('any' => __('Any', 'Render')), 'callback' => array('function' => 'render_sc_post_type_list')));
            break;
        case 'terms_list':
            $output = array('label' => __('Terms', 'Render'), 'type' => 'selectbox', 'properties' => array('callback' => array('function' => 'render_sc_term_list', 'args' => $args), 'placeholder' => __('Select a taxonomy to get terms from.', 'Render')));
            break;
        case 'timezone':
            $output = array('label' => __('Timezone', 'Render'), 'type' => 'selectbox', 'advanced' => true, 'properties' => array('placeholder' => __('Defaults to timezone set in Settings -> General', 'Render'), 'callback' => array('function' => 'render_sc_timezone_dropdown')));
            break;
        case 'link':
            $output = array('label' => __('Link', 'Render'), 'description' => __('Links to a post / page.', 'Render'), 'type' => 'selectbox', 'properties' => array('placeholder' => __('Select a post / page, or type a link', 'Render'), 'allowCustomInput' => true, 'callback' => array('function' => 'render_sc_post_list', 'args' => $args)));
            break;
        case 'phone':
            $output = array('label' => __('Phone', 'Render'), 'properties' => array('prefix' => '<span class="dashicons dashicons-phone"></span>', 'prefixWidth' => 15, 'mask' => array('template' => 'phone')));
            break;
        case 'email':
            $output = array('label' => __('Email', 'Render'), 'properties' => array('prefix' => '<span class="dashicons dashicons-email"></span>', 'prefixWidth' => 15), 'validate' => array('EMAIL' => true));
            break;
        case 'border-radius':
            $orientation = isset($args['orientation']) ? $args['orientation'] : '';
            $output = array('label' => sprintf(__('Border %s Radius', 'Render'), $orientation), 'advanced' => true, 'type' => 'counter', 'properties' => array('shift_step' => 20, 'unit' => array('default' => 'px', 'allowed' => array('px', '%', 'em', 'rem', 'pt'))));
            break;
        case 'post_order':
            $output = array('label' => __('Order', 'Render'), 'type' => 'toggle', 'properties' => array('values' => array('DSC' => __('Descending', 'Render'), 'ASC' => __('Ascending', 'Render'))));
            break;
        case 'post_orderby':
            $output = array('label' => __('Order by', 'Render'), 'type' => 'selectbox', 'default' => 'date', 'properties' => array('options' => array('none' => __('None', 'Render'), 'ID' => __('Post ID', 'Render'), 'author' => __('Author', 'Render'), 'title' => __('Title', 'Render'), 'name' => __('Name (slug)', 'Render'), 'type' => __('Post Type', 'Render'), 'date' => __('Date', 'Render'), 'modified' => __('Last Modified', 'Render'), 'parent' => __('Parent', 'Render'), 'rand' => __('Random', 'Render'), 'comment_count' => __('Comment Count', 'Render'), 'menu_order' => __('Menu Order', 'Render'))));
            break;
    }
    /**
     * Allows more templates to be used.
     *
     * Simply call this filter, do your own switch case with various templates and output methods, and return the output.
     * Just be sure to return the output, unmodified, if your switch case does not match anything.
     *
     * @since 1.0.3
     */
    $output = apply_filters('render_sc_attr_templates', $output, $template, $extra, $args);
    // Reset timezone
    date_default_timezone_set($orig_timezone);
    // Merge in the extra overrides
    if (!empty($extra)) {
        $output = array_replace_recursive($output, $extra);
    }
    return $output;
}