Пример #1
0
/**
 * Get Attachment Meta
 *
 * Returns the attachment meta field.
 * Use to get title, caption, description
 * Or anything else listed here:
 * https://codex.wordpress.org/Function_Reference/wp_prepare_attachment_for_js
 *
 * @param int $post_id
 * @param int $field
 * @uses wp_prepare_attachment_for_js();
 * @return string field (id, caption, title, description, etc)
 * @since 2.0.4
 */
function sell_media_get_attachment_meta($post_id = null, $field = 'id')
{
    if (sell_media_has_multiple_attachments($post_id)) {
        $attachment_id = get_query_var('id');
    } else {
        $attachments = sell_media_get_attachments($post_id);
        $attachment_id = $attachments[0];
    }
    $attachment_meta = wp_prepare_attachment_for_js($attachment_id);
    return $attachment_meta[$field];
}
Пример #2
0
/**
 * Files meta box
 */
function sell_media_files_meta_box($post)
{
    wp_nonce_field('_sell_media_meta_box_nonce', 'sell_media_meta_box_nonce');
    do_action('sell_media_before_files_meta_box', $post);
    ?>

    <div id="sell-media-upload-field" class="sell-media-field">
        <p><input type="button" class="sell-media-upload-button button" data-id="<?php 
    echo $post->ID;
    ?>
" value="<?php 
    _e('Upload', 'sell_media');
    ?>
" /></p>
        <p class="description"><?php 
    _e('Upload one file to create a single product or many files to create a gallery.', 'sell_media');
    ?>
</p>
        <p class="description"><a href="#" class="sell-media-upload-options"><span class="dashicons dashicons-arrow-down"></span> <?php 
    _e('Importing Options', 'sell_media');
    ?>
</a></p>
    </div>

    <div id="sell-media-upload-show-options" class="sell-media-upload-show-options" style="display:none;">
        <h4><?php 
    _e('Importing', 'sell_media');
    ?>
</h4>
        <p class="description"><?php 
    printf(__('Quickly import folders of images using this option. Use FTP or <a href="%1$s" target="_blank">export directly from Lightroom</a> and place new folders into the server path listed below. Then, select the folder below to import into WordPress.', 'sell_media'), 'http://graphpaperpress.com/docs/sell-media/#add-bulk');
    ?>
</p>
        <p class="description"><strong><?php 
    _e('Server Path', 'sell_media');
    ?>
:</strong> <?php 
    echo sell_media_get_import_dir();
    ?>
</p>
        <select id="sell-media-upload-bulk-selector" value="">
            <option value=""><?php 
    _e('Select a folder', 'sell_media');
    ?>
</option>
            <?php 
    $directories = sell_media_get_directories();
    if ($directories) {
        foreach ($directories as $directory) {
            ?>
                <option value="<?php 
            echo basename($directory);
            ?>
"><?php 
            echo basename($directory);
            ?>
</option>
            <?php 
        }
    }
    ?>
        </select>
        <button id="sell-media-upload-bulk-processor" type="button" class="button button-large" data-default-text="<?php 
    _e('Add more files', 'sell_media');
    ?>
" data-uploading-text="<?php 
    _e('Importing files...', 'sell_media');
    ?>
" disabled><?php 
    _e('Add files', 'sell_media');
    ?>
</button><br /><br />
        <?php 
    do_action('sell_media_after_files_show_options_meta_box', $post);
    ?>
    </div>

    <?php 
    if (Sell_Media()->products->is_package($post->ID)) {
        ?>
        <div id="sell-media-packages" class="sell-media-field">
            <h4><?php 
        _e('Packages', 'sell_media');
        ?>
</h4>
            <p><?php 
        _e('This feature was retired in version 2.0 because product galleries can now be created. Your old package file will still be available for sale and is listed below.', 'sell_media');
        ?>
</p>
            <p><strong><?php 
        echo get_post_meta($post->ID, '_sell_media_attached_file', true);
        ?>
</strong></p>
        </div>
    <?php 
    }
    ?>

    <ul class="attachments sell-media-upload-list">
        <?php 
    $attachment_ids = sell_media_get_attachments($post->ID);
    if ($attachment_ids) {
        foreach ($attachment_ids as $attachment_id) {
            echo sell_media_list_uploads($attachment_id);
        }
    }
    ?>
    </ul>

    <?php 
    do_action('sell_media_after_files_meta_box', $post);
    ?>
    <!-- This hidden field holds all attached file ids -->
    <input type="hidden" name="_sell_media_attachment_id" id="sell-media-attachment-id" class="sell-media-attachment-id" value="<?php 
    echo !empty($attachment_ids) ? implode(',', $attachment_ids) : '';
    ?>
"/>
<?php 
}
Пример #3
0
 /**
  * Checks if the post has image attachments
  *
  * @param $attachment_id ID of the attachment
  * @return boolean true/false
  * @since 1.6.9
  */
 public function has_image_attachments($post_id = null)
 {
     $attachment_ids = sell_media_get_attachments($post_id);
     if ($attachment_ids) {
         foreach ($attachment_ids as $attachment_id) {
             if (wp_attachment_is_image($attachment_id)) {
                 return true;
             }
         }
     }
 }
Пример #4
0
/**
 * Display Gallery Image Navigation
 *
 * @param $attachment_id
 * @return html the previous image / next image links
 * @since 2.0.1
 */
function sell_media_gallery_navigation($attachment_id)
{
    global $post;
    $attachment_ids = sell_media_get_attachments($post->ID);
    $current_image = array_search($attachment_id, $attachment_ids);
    $html = '<span class="sell-media-gallery-navigation">';
    if (array_key_exists($current_image - 1, $attachment_ids)) {
        $html .= '<a href="' . esc_url(add_query_arg('id', $attachment_ids[$current_image - 1], get_permalink())) . '" class="sell-media-gallery-prev" title="' . __('Previous Image', 'sell_media') . '"><span class="dashicons dashicons-arrow-left-alt"></span> ' . __('Previous', 'sell_media') . '</a>';
    }
    $html .= '<a href="' . get_permalink() . '"class="sell-media-gallery-index" title="' . __('Back to Gallery', 'sell_media') . '"><span class="dashicons dashicons-screenoptions"></span> ' . __('Gallery', 'sell_media') . '</a>';
    if (array_key_exists($current_image + 1, $attachment_ids)) {
        $html .= '<a href="' . esc_url(add_query_arg('id', $attachment_ids[$current_image + 1], get_permalink())) . '"class="sell-media-gallery-next" title="' . __('Next Image', 'sell_media') . '">' . __('Next', 'sell_media') . ' <span class="dashicons dashicons-arrow-right-alt"></span></a>';
    }
    $html .= '</span>';
    return apply_filters('sell_media_gallery_navigation', $html, $attachment_id);
}