Plugin Directory

Changeset 1712261


Ignore:
Timestamp:
08/11/2017 07:00:31 PM (9 years ago)
Author:
stephenafamo
Message:

removing redundant code

Location:
html-php-pages-and-posts/trunk
Files:
2 edited

Legend:

Unmodified
Added
Removed
  • html-php-pages-and-posts/trunk/html-php-pages-and-posts.php

    r1706752 r1712261  
    293293
    294294// Begin!!!
     295$attributes = [];
    295296$attributes['plugin_name'] = 'html-php-pages-and-posts';
    296297$attributes['default_post_types'] = ["post", "page"];
  • html-php-pages-and-posts/trunk/partials/uploader.js

    r1693375 r1712261  
    1 jQuery( document ).ready( function( $ ) {
    2     var wp_media_post_id = wp.media.model.settings.post.id; // Store the old id
    3     console.log(wp_media_post_id);
    4     // Restore the main ID when the add media button is pressed
    5     // jQuery( 'a.add_media' ).on( 'click', function() {
    6     //     wp.media.model.settings.post.id = wp_media_post_id;
    7     // });
    8 });
     1function delete_template(event, prefix = "", suffix = "")
     2{
     3    var nothing = '';
     4    document.getElementById(prefix + 'agadyn_custom_template_path' + suffix ).value = nothing;
     5    document.getElementById(prefix + 'agadyn_custom_template_id' + suffix ).value = nothing;
     6}
    97
     8function select_template(event, prefix = "", suffix = "")
     9{
     10    var file_frame;
     11    var wp_media_post_id = wp.media.model.settings.post.id;
     12    var set_to_post_id = document.getElementById(prefix + 'agadyn_custom_template_id' + suffix).value; // Set this
    1013
    11     function delete_template(event, prefix = "", suffix = "")
    12     {
    13         var nothing = '';
    14         document.getElementById(prefix + 'agadyn_custom_template_path' + suffix ).value = nothing;
    15         document.getElementById(prefix + 'agadyn_custom_template_id' + suffix ).value = nothing;
     14    event.preventDefault();
     15    // If the media frame already exists, reopen it.
     16    if ( file_frame ) {
     17        // Set the post ID to what we want
     18        file_frame.uploader.uploader.param( 'post_id', set_to_post_id );
     19        // Open frame
     20        file_frame.open();
     21        return;
     22    } else {
     23        // Set the wp.media post id so the uploader grabs the ID we want when initialised
     24        wp.media.model.settings.post.id = set_to_post_id;
    1625    }
    17 
    18     function select_template(event, prefix = "", suffix = "")
    19     {
    20         var file_frame;
    21         var wp_media_post_id = wp.media.model.settings.post.id;
    22         var set_to_post_id = document.getElementById(prefix + 'agadyn_custom_template_id' + suffix).value; // Set this
    23 
    24         event.preventDefault();
    25         // If the media frame already exists, reopen it.
    26         if ( file_frame ) {
    27             // Set the post ID to what we want
    28             file_frame.uploader.uploader.param( 'post_id', set_to_post_id );
    29             // Open frame
    30             file_frame.open();
    31             return;
    32         } else {
    33             // Set the wp.media post id so the uploader grabs the ID we want when initialised
    34             wp.media.model.settings.post.id = set_to_post_id;
    35         }
    36         // Create the media frame.
    37         file_frame = wp.media.frames.file_frame = wp.media({
    38             title: 'Select a template to upload',
    39             button: {
    40                 text: 'Use this template',
    41             },
    42             multiple: false // Set to true to allow multiple files to be selected
    43         });
    44         // When an image is selected, run a callback.
    45         file_frame.on( 'select', function() {
    46             // We set multiple to false so only get one image from the uploader
    47             attachment = file_frame.state().get('selection').first().toJSON();
    48             // Do something with attachment.id and/or attachment.url here
    49             document.getElementById(prefix + 'agadyn_custom_template_path' + suffix ).value = attachment.url;
    50             document.getElementById(prefix + 'agadyn_custom_template_id' + suffix ).value = attachment.id;
    51             // Restore the main post ID
    52             wp.media.model.settings.post.id = wp_media_post_id;
    53         });
    54         // Finally, open the modal
    55         file_frame.open();
    56     }
     26    // Create the media frame.
     27    file_frame = wp.media.frames.file_frame = wp.media({
     28        title: 'Select a template to upload',
     29        button: {
     30            text: 'Use this template',
     31        },
     32        multiple: false // Set to true to allow multiple files to be selected
     33    });
     34    // When an image is selected, run a callback.
     35    file_frame.on( 'select', function() {
     36        // We set multiple to false so only get one image from the uploader
     37        attachment = file_frame.state().get('selection').first().toJSON();
     38        // Do something with attachment.id and/or attachment.url here
     39        document.getElementById(prefix + 'agadyn_custom_template_path' + suffix ).value = attachment.url;
     40        document.getElementById(prefix + 'agadyn_custom_template_id' + suffix ).value = attachment.id;
     41        // Restore the main post ID
     42        wp.media.model.settings.post.id = wp_media_post_id;
     43    });
     44    // Finally, open the modal
     45    file_frame.open();
     46}
Note: See TracChangeset for help on using the changeset viewer.