/** * Install * * Runs on plugin install by setting up the post types, custom taxonomies, * flushing rewrite rules to initiate the new 'sell_media_item' slug and also * creates the plugin and populates the settings fields for those plugin * pages. * * @since 1.8.5 * @global $wpdb * @global $wp_version * @return void */ function sell_media_install() { $version = get_option('sell_media_version'); if ($version && $version > SELL_MEDIA_VERSION) { return; } // Register Custom Post Types sell_media_register_post_types(); // Register Taxonomies sell_media_register_taxonomies(); // Flush the permalinks flush_rewrite_rules(); // Don't forget registration hook is called // BEFORE! taxonomies are registered! therefore // these terms and taxonomies are NOT derived from our object! $settings = sell_media_get_plugin_options(); $admin_columns = empty($settings->admin_columns) ? null : $settings->admin_columns; // Install new table for term meta $taxonomy_metadata = new SellMediaTaxonomyMetadata(); $taxonomy_metadata->activate(); $taxonomy = 'licenses'; // Add Personal and Commerical default license terms $r_personal = wp_insert_term('Personal', $taxonomy, array('slug' => 'personal')); $r_commercial = wp_insert_term('Commercial', $taxonomy, array('slug' => 'commercial')); // Install protected folder for uploading files and prevent hotlinking $downloads_url = sell_media_get_upload_dir(); if (wp_mkdir_p($downloads_url) && !file_exists($downloads_url . '/.htaccess')) { if ($file_handle = @fopen($downloads_url . '/.htaccess', 'w')) { fwrite($file_handle, 'deny from all'); fclose($file_handle); } } // Add a new Customer role add_role('sell_media_customer', 'Customer', array('read' => true)); // This is a new install so add the defaults to the options table if (empty($version)) { $defaults = sell_media_get_plugin_option_defaults(); update_option(sell_media_get_current_plugin_id() . "_options", $defaults); // A version number exists, so run upgrades } else { require_once SELL_MEDIA_PLUGIN_DIR . '/inc/admin-upgrade.php'; } // Update the version number update_option('sell_media_version', SELL_MEDIA_VERSION); }
/** * Callback for get_settings_field() */ function sell_media_plugin_setting_callback($option) { $sell_media_options = (array) sell_media_get_plugin_options(); $option_parameters = sell_media_get_plugin_option_parameters(); $optionname = $option['name']; $optiontitle = $option['title']; $optiondescription = $option['description']; $fieldtype = $option['type']; $fieldname = sell_media_get_current_plugin_id() . "_options[ { {$optionname} } ]"; $attr = $option_parameters[$option['name']]; $value = $sell_media_options[$optionname]; //Determine the type of input field switch ($fieldtype) { //Render Text Input case 'text': sell_media_plugin_field_text($value, $attr); echo '<span class="option-description">' . $option['description'] . '</span>'; break; //Render Password Input //Render Password Input case 'password': sell_media_plugin_field_password($value, $attr); echo '<span class="option-description">' . $option['description'] . '</span>'; break; //Render textarea options //Render textarea options case 'textarea': sell_media_plugin_field_textarea($value, $attr); echo '<span class="option-description">' . $option['description'] . '</span>'; break; //Render select dropdowns //Render select dropdowns case 'select': sell_media_plugin_field_select($value, $attr); echo '<span class="option-description">' . $option['description'] . '</span>'; break; //Render radio dropdowns //Render radio dropdowns case 'radio': sell_media_plugin_field_radio($value, $attr); echo '<span class="option-description">' . $option['description'] . '</span>'; break; //Render radio image dropdowns //Render radio image dropdowns case 'radio_image': sell_media_plugin_field_radio_image($value, $attr); echo '<span class="option-description">' . $option['description'] . '</span>'; break; //Render checkboxes //Render checkboxes case 'checkbox': sell_media_plugin_field_checkbox($value, $attr); echo '<span class="option-description">' . $option['description'] . '</span>'; break; //Render color picker //Render color picker case 'color': sell_media_plugin_field_color($value, $attr); echo '<span class="option-description">' . $option['description'] . '</span>'; break; //Render uploaded image //Render uploaded image case 'image': sell_media_plugin_field_image($value, $attr); echo '<span class="option-description">' . $option['description'] . '</span>'; break; //Render uploaded gallery //Render uploaded gallery case 'gallery': sell_media_plugin_field_gallery($value, $attr); echo '<span class="option-description">' . $option['description'] . '</span>'; break; //Render uploaded gallery //Render uploaded gallery case 'html': sell_media_plugin_field_html($value, $attr); echo '<span class="option-description">' . $option['description'] . '</span>'; break; default: break; } }
function sell_media_plugin_field_gallery($value, $attr) { $images = explode(',', $value); $imgarray = ''; foreach ($images as $imageID) { $image = wp_get_attachment_image_src($imageID); $imgarray .= '<img class="eachthumbs" src="' . $image[0] . '" style="cursor:pointer;height:60px;width:auto;margin:5px 5px 0 0;"/>'; } ?> <script language="javascript"> jQuery(document).ready(function() { $container = jQuery("#<?php echo $attr['name']; ?> _container"); $image_field = $container.find('.upload_gallery_field'); $image_button = $container.find('.upload_gallery_button'); $remove_button = $container.find('.sell_media_gallery_remove'); $image_button.click(function() { // WordPress 3.5 Media Pop Up var file_frame; // Create the media frame. file_frame = wp.media.frames.file_frame = wp.media({ title: 'Select Images', button: { text: 'Use Selected Images', }, multiple: 'add' }); // When an image is selected, run a callback. file_frame.on( 'select', function() { hiddenids = ''; jQuery( '.upload_gallery_preview' ).html(''); var selection = file_frame.state().get( 'selection' ); selection.map( function( attachment ) { attachment = attachment.toJSON(); hiddenids += attachment.id + ','; $container.find( '.upload_gallery_preview' ).show(); jQuery( '.upload_gallery_preview' ).append( '<img style=\"cursor:pointer;height:60px;width:auto;margin:5px 5px 0 0;\" class=\'eachthumbs\' src=\"' + attachment.url + '\"/>' ); }); jQuery( '.upload_gallery_preview' ).append( '<br /><a href="javascript:void(0);" class="upload_gallery_remove">Remove</a>' ); $container.find( '.upload_gallery_field' ).val( hiddenids.substring( 0, hiddenids.length - 1 ) ).show(); }); // open the modal file_frame.open(); return false; }); jQuery( '.upload_gallery_preview' ).on( 'click', '.eachthumbs', function() { // edit gallery var file_frame, selection; var hiddenids = ''; var hiddenids = jQuery( '.upload_gallery_field' ).val(); var gallerysc = '[gallery ids=' + hiddenids + ']'; file_frame = wp.media.gallery.edit( gallerysc ); // need to replace [gallery] with actual shortcode file_frame.on( 'update', function( selection ) { jQuery( '.upload_gallery_preview' ).html( '<img src=\"" . site_url() . "/wp-includes/images/wpspin.gif" . "\" />' ); var addedgallery = wp.media.gallery.shortcode( selection ).string(); var idarray = addedgallery.split( '=\"' ); datanew = idarray[1].substring( 0, idarray[1].length - 2 ); jQuery.post( ajaxurl, { action: 'sell_media_imageurl', ids: datanew, pid: jQuery( '.upload_gallery_field' ).val() }, function( response ) { jQuery( '.upload_gallery_field' ).val( datanew ); jQuery( '.upload_gallery_preview' ).html( response ); }); }); return false; }); // remove image jQuery( '.upload_gallery_preview' ).on( 'click', '.upload_gallery_remove', function() { jQuery( '.upload_gallery_field' ).val( '' ); jQuery( '.upload_gallery_preview' ).hide(); }); if ( jQuery( '.upload_gallery_field' ).val().length > 0 ) { jQuery( '.upload_gallery_preview' ).show(); } }); </script> <div id="<?php echo $attr['name']; ?> _container"> <input type="hidden" class="upload_gallery_field" id="<?php echo $attr['name']; ?> " name="<?php echo sell_media_get_current_plugin_id(); ?> _options[<?php echo $attr['name']; ?> ]" value="<?php echo $value; ?> "> <input class="upload_gallery_button button" type="button" value="<?php _e('Upload or Select Images', 'sell_media'); ?> " /> <div class="upload_gallery_preview"><?php if ('' != $value) { echo $imgarray; ?> <br /><a href="javascript:void(0);" class="upload_gallery_remove"><?php _e('Remove', 'sell_media'); ?> </a><?php } ?> </div> </div> <?php }