Forum Replies Created

Viewing 15 replies - 16 through 30 (of 52 total)
  • Thread Starter openbayou

    (@openbayou)

    Now it’s done. Thanks again for the help.

    function analyize_mp3_add_meta_box() {
    	add_meta_box(
    		'analyize_mp3-analyize-mp3',
    		__( 'Analyize MP3', 'analyize_mp3' ),
    		'analyize_mp3_html',
    		'post',
    		'normal',
    		'default'
    	);
    }
    add_action( 'add_meta_boxes', 'analyize_mp3_add_meta_box' );
    function analyize_mp3_html( $post) {
    	wp_nonce_field( '_analyize_mp3_nonce', 'analyize_mp3_nonce' ); ?>
    
    <script type="text/javascript" src="//code.jquery.com/jquery-1.9.1.js"></script>
    <style type="text/css">
        audio {
        display: none;
    }
      </style>
    <script type='text/javascript'>//<![CDATA[
    $(function(){
    var objectUrl;
    
    $("#audio").on("canplaythrough", function(e){
        var seconds = e.currentTarget.duration;
        var duration = moment.duration(seconds, "seconds");
        
        var time = "";
        var hours = duration.hours();
        if (hours > 0) { time = hours + ":" ; }
        
        time = time + duration.minutes() + ":" + duration.seconds();
        $("#duration").text(time);
        $('#timelength').val(time);
        
        URL.revokeObjectURL(objectUrl);
    });
    
    $("#file").change(function(e){
        var file = e.currentTarget.files[0];
       
        $("#filesize").text(file.size);
        $('#size').val(file.size);
        
        objectUrl = URL.createObjectURL(file);
        $("#audio").prop("src", objectUrl);
    });
    
    });//]]> 
    
    </script>
    
    <p>Select a .mp3 file</p>
    <input type="file" id="file" />
    
    <audio id="audio"></audio>
    
    <p>
      <label>File Size:</label>
      <span id="filesize"></span>
      <input type="hidden" id="size" name="size" value=""/>
    </p>
    
    <p>
      <label>Song Duration:</label>
      <span id="duration"></span>
      <input type="hidden" id="timelength" name="time" value=""/>
    </p>
        
        <?php
    }
    
    function analyize_mp3_save( $post_id ) {
    	if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
    	if ( ! isset( $_POST['analyize_mp3_nonce'] ) || ! wp_verify_nonce( $_POST['analyize_mp3_nonce'], '_analyize_mp3_nonce' ) ) return;
    	if ( ! current_user_can( 'edit_post', $post_id ) ) return;
    
        if ( isset( $_POST['size'] ) )
        if (!empty($_POST["size"])) {;
            update_post_meta( $post_id, 'length', sanitize_text_field( $_POST['size'] ));
        };
        if ( isset( $_POST['time'] ) )
        if (!empty($_POST["time"])) {;
            update_post_meta( $post_id, 'time', sanitize_text_field( $_POST['time'] ));
        };
    }
    add_action( 'save_post', 'analyize_mp3_save' );
    Thread Starter openbayou

    (@openbayou)

    I was able to figure out my problem (feel free to point out any problems with my code below) but the problem is that when I update a post, the custom fields get erased. Is there a way to not clear the custom fields when a post is being updated unless the input fields have a value in them?

    function analyize_mp3_add_meta_box() {
    	add_meta_box(
    		'analyize_mp3-analyize-mp3',
    		__( 'Analyize MP3', 'analyize_mp3' ),
    		'analyize_mp3_html',
    		'post',
    		'normal',
    		'default'
    	);
    }
    add_action( 'add_meta_boxes', 'analyize_mp3_add_meta_box' );
    function analyize_mp3_html( $post) {
    	wp_nonce_field( '_analyize_mp3_nonce', 'analyize_mp3_nonce' ); ?>
    
    <script type="text/javascript" src="//code.jquery.com/jquery-1.9.1.js"></script>
    <style type="text/css">
        audio {
        display: none;
    }
      </style>
    <script type='text/javascript'>//<![CDATA[
    $(function(){
    var objectUrl;
    
    $("#audio").on("canplaythrough", function(e){
        var seconds = e.currentTarget.duration;
        var duration = moment.duration(seconds, "seconds");
        
        var time = "";
        var hours = duration.hours();
        if (hours > 0) { time = hours + ":" ; }
        
        time = time + duration.minutes() + ":" + duration.seconds();
        $("#duration").text(time);
        $('#timelength').val(time);
        
        URL.revokeObjectURL(objectUrl);
    });
    
    $("#file").change(function(e){
        var file = e.currentTarget.files[0];
       
        $("#filesize").text(file.size);
        $('#size').val(file.size);
        
        objectUrl = URL.createObjectURL(file);
        $("#audio").prop("src", objectUrl);
    });
    
    });//]]> 
    
    </script>
    
    <p>Select a .mp3 file</p>
    <input type="file" id="file" />
    
    <audio id="audio"></audio>
    
    <p>
      <label>File Size:</label>
      <span id="filesize"></span>
      <input type="hidden" id="size" name="size" value=""/>
    </p>
    
    <p>
      <label>Song Duration:</label>
      <span id="duration"></span>
      <input type="hidden" id="timelength" name="time" value=""/>
    </p>
        
        <?php
    }
    
    function analyize_mp3_save( $post_id ) {
    	if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) return;
    	if ( ! isset( $_POST['analyize_mp3_nonce'] ) || ! wp_verify_nonce( $_POST['analyize_mp3_nonce'], '_analyize_mp3_nonce' ) ) return;
    	if ( ! current_user_can( 'edit_post', $post_id ) ) return;
    
    	if ( isset( $_REQUEST['size'] ) )
            update_post_meta( $post_id, 'length', sanitize_text_field( $_POST['size'] ));
        if ( isset( $_REQUEST['time'] ) )
            update_post_meta( $post_id, 'time', sanitize_text_field( $_POST['time'] ));
    }
    add_action( 'save_post', 'analyize_mp3_save' );

    Thanks again for the help, I really appreciate it.

    Thread Starter openbayou

    (@openbayou)

    Nevermind, was able to figure it out $('#metavalue').val(file.size);

    Thread Starter openbayou

    (@openbayou)

    Update: I’ve changed $('input[name="size"]').val(text(file.size)); to
    $('#metavalue').val($("#filesize").text(file.size)); and the input value is [object Object]

    Thread Starter openbayou

    (@openbayou)

    Thanks for the info. So how do I save data to an input? I’ve tried $("#metavalue").val(); and it didn’t save it to the input.

    Thread Starter openbayou

    (@openbayou)

    Thanks for the response. You’ve given me a lot of useful information that never occurred to me, especially using the where query and update function just using math.

    Thread Starter openbayou

    (@openbayou)

    Sorry but I’m using another plugin. I was able to solved the problem by making a JS code that automatically checks the site when I create a new post.

    • This reply was modified 7 years, 5 months ago by openbayou.
    Thread Starter openbayou

    (@openbayou)

    Update: It turns out the plugin I’m using is the problem. I found another plugin that does the same thing and the problem doesn’t occur when the post is copied from one site to another.

    Thanks for the help.

    • This reply was modified 7 years, 6 months ago by openbayou.
    Thread Starter openbayou

    (@openbayou)

    Still does duplicate revisions and the plugin double posted to the copied site.

    Thread Starter openbayou

    (@openbayou)

    Never mind, problem with my ‘pre_get_posts’

    Thread Starter openbayou

    (@openbayou)

    Fixed by problem with jQuery

    jQuery(document).ready(function($){
      multisite_check_sync($);
    });
     
    function multisite_check_sync($) {
      setTimeout(function() {$('a#mpd-select-all').click();}, 100); 
      setTimeout(function() {$('.cdl input').attr('checked', true);}, 200); 
    }

    What the code does above is click on a link called #mpd-select-all after 100ms, it then unhides an element and then 200ms later, it checks an input.

    In my theme’s functions.php, I call up the script in my theme’s folder

    wp_enqueue_script( 'admin-check', get_template_directory_uri() . '/js/admin.js', array ( 'jquery' ), 1, true);
    
    • This reply was modified 7 years, 6 months ago by openbayou.
    Thread Starter openbayou

    (@openbayou)

    Is there a way to run jQuery on the admin panel? Either through a plugin or in a theme’s functions.php?

    Thread Starter openbayou

    (@openbayou)

    Ok, I figured out my problem. Is there a way to have a site selected by default? Also if I make changes to a post not on the master, how can it sync those changes back to the main site.

    • This reply was modified 7 years, 6 months ago by openbayou.
    Thread Starter openbayou

    (@openbayou)

    wp_posts and . .

    Thread Starter openbayou

    (@openbayou)

    Last question: Does Google index the repeater template or not?

Viewing 15 replies - 16 through 30 (of 52 total)