예제 #1
0
/**
 * Display our copy-able code for registered post types.
 *
 * @since 1.0.0
 *
 * @return string Post type registration text for use elsewhere.
 */
function cptui_get_post_type_code()
{
    $cptui_post_types = get_option('cptui_post_types');
    # Whitespace very much matters here, thus why it's all flush against the left side
    if (!empty($cptui_post_types)) {
        ?>
add_action( 'init', 'cptui_register_my_cpts' );
function cptui_register_my_cpts() {
<?php 
        #space before this line reflects in textarea
        foreach ($cptui_post_types as $type) {
            echo cptui_get_single_post_type_registery($type) . "\n";
        }
        ?>
// End of cptui_register_my_cpts()
}
<?php 
    } else {
        _e('No post types to display at this time', 'cpt-plugin');
    }
}
/**
 * Display our copy-able code for registered post types.
 *
 * @since 1.0.0
 * @since 1.2.0 Added $cptui_post_types parameter.
 * @since 1.2.0 Added $single parameter.
 *
 * @param array $cptui_post_types Array of post types to render.
 * @param bool  $single           Whether or not we are rendering a single post type.
 * @return string Post type registration text for use elsewhere.
 */
function cptui_get_post_type_code($cptui_post_types = array(), $single = false)
{
    // Whitespace very much matters here, thus why it's all flush against the left side.
    if (!empty($cptui_post_types)) {
        $callback = 'cptui_register_my_cpts';
        if ($single) {
            $key = key($cptui_post_types);
            $callback = 'cptui_register_my_cpts_' . str_replace('-', '_', $cptui_post_types[$key]['name']);
        }
        ?>
add_action( 'init', '<?php 
        echo $callback;
        ?>
' );
function <?php 
        echo $callback;
        ?>
() {
<?php 
        // space before this line reflects in textarea.
        foreach ($cptui_post_types as $type) {
            echo cptui_get_single_post_type_registery($type) . "\n";
        }
        ?>
// End of <?php 
        echo $callback;
        ?>
()
}
<?php 
    } else {
        _e('No post types to display at this time', 'custom-post-type-ui');
    }
}