Forum Replies Created

Viewing 15 replies - 1 through 15 (of 48 total)
  • Thread Starter morgyface

    (@morgyface)

    Can’t thank you enough @dr.mykola, I could not have worked that out, I’m sure others will be grateful too. I can confirm it works a treat!

    Thread Starter morgyface

    (@morgyface)

    I’m very grateful for the response, my confusion comes from the fact that when I move databases between, local, dev, staging and production, the Mail data tab is only populated on the site where it was added. So whilst the form content exists across the board, the mail tab is empty on all sites apart from the site where the duplicated database came from, this causes any submissions to fail. This means that every time I move databases, I need to manually re-add the mail tab data. Why does this happen? Is there a workaround?

    To further illustrate; The client is currently populating content on dev, when they let me know I download the database, find/replace the URL and then import to production. This works perfectly, apart from the mail tab is empty on production. It’s populated and works on dev, but is empty on production. This means that following import, I must then log-in and manually re-add all the mail tab data.

    Will this be a single post object or multiple post objects?

    Yup, I’m getting this also. Still seems to work but the warning appears at the top of the uC options page when saving settings.

    Hey Bongo,

    I could be way off but I’ve successfully sanitized filenames before.

    Have a little look at this and see if it helps:

    sanitize file name

    Thread Starter morgyface

    (@morgyface)

    Here’s the complete solution which you’d add to functions.php:

    function crop_settings_api_init() {
    	// Add the section to media settings
    	add_settings_section(
    		'crop_settings_section',
    		'Crop images',
    		'crop_settings_callback_function',
    		'media'
    	);
    	// Add the fields to the new section
    	add_settings_field(
    		'medium_crop',
    		'Medium size crop',
    		'crop_medium_callback_function',
    		'media',
    		'crop_settings_section'
    	);
    	add_settings_field(
    		'large_crop',
    		'Large size crop',
    		'crop_large_callback_function',
    		'media',
    		'crop_settings_section'
    	);
    	register_setting( 'media', 'medium_crop' );
    	register_setting( 'media', 'large_crop' );
    } // crop_settings_api_init()
    
    add_action( 'admin_init', 'crop_settings_api_init', 1 );
    
    // Settings section callback function
    function crop_settings_callback_function() {
        echo '<p>Choose whether to crop the medium and large size images</p>';
    }
    // Callback function for our medium crop setting
    function crop_medium_callback_function() {
    	echo '<input name="medium_crop" type="checkbox" id="medium_crop" value="1"';
        $mediumcrop = get_option( "medium_crop");
        if ( $mediumcrop == 1 ) {
            echo ' checked';
    	}
    	echo '/>';
    	echo '<label for="medium_crop">Crop medium to exact dimensions</label>';
    }
    // Callback function for our large crop setting
    function crop_large_callback_function() {
    	echo '<input name="large_crop" type="checkbox" id="large_crop" value="1"';
        $largecrop = get_option( "large_crop");
        if ( $largecrop == 1 ) {
            echo ' checked';
    	}
    	echo '/>';
    	echo '<label for="large_crop">Crop large to exact dimensions</label>';
    }

    I’ve also created a gist here and will, when time permits, create a plugin.

    Thanks again for your help @bcworkz!

    Thread Starter morgyface

    (@morgyface)

    Well thanks to your nudge and ongoing support @bcworkz I’ve only gone and got it flippin’ working, I changed the add_settings_field id to medium_crop to match the existing option and field and also added an add_action priority of 1 and it retains the checked status and crops. I’ve tried checking, unchecking, and uploading images in both situations and all seems good. I’m now thinking I’ll add a large crop option and bundle it all up. I might even build my first plug-in. I shall post again shortly with the complete solution for the benefit of others.

    Thread Starter morgyface

    (@morgyface)

    Thread Starter morgyface

    (@morgyface)

    I’m closing this thread down as it’s kinda gone off piste as it’s developed, I’ll re-word and create a new more specific question.

    Thread Starter morgyface

    (@morgyface)

    Hello again, so I’ve managed to do this:

    function crop_settings_api_init() {
    	// Add the section to media settings
    	add_settings_section(
    		'crop_settings_section',
    		'Crop images',
    		'crop_settings_callback_function',
    		'media'
    	);
    	// Add the fields to the new section
    	add_settings_field(
    		'medium_cropping',
    		'Medium size crop',
    		'crop_medium_callback_function',
    		'media',
    		'crop_settings_section'
    	);
    	register_setting( 'media', 'medium_cropping' );
    } // crop_settings_api_init()
    
    add_action( 'admin_init', 'crop_settings_api_init' );
    
    // Settings section callback function
    function crop_settings_callback_function() {
        echo '<p>Choose whether to also crop the medium size image</p>';
    }
    // Callback function for our medium crop setting
    function crop_medium_callback_function() {
    	echo '<input name="medium_crop" type="checkbox" id="medium_crop" value="1"' . checked( 1, get_option( 'medium_crop' )) . '/>';
    	echo '<label for="medium_crop">Crop medium to exact dimensions</label>';
    }

    Visually, this looks exactly as I want it. However I now need to make it work. How do I now combine it with…

    if ( get_option( "medium_crop") !== false ) {
        update_option("medium_crop", "1");
    } else {
        add_option("medium_crop", "1");
    }

    …to create the full hack?

    NB. I’ve called the settings field medium_cropping, however the existing option is called medium_crop, have I done the right thing here?

    Thread Starter morgyface

    (@morgyface)

    Thanks again for your help and direction @bcworkz, because it’s not possible to be specific with the location of new fields, I’m thinking one option would be to remove the crop thumbnail option and, instead, create a new section under “Image sizes” called “Image cropping” and there have a crop option for each of the sizes. I just need to cobble it all together now.

    It looks like the code is in wp-admin/options-media.php

    <input name="thumbnail_crop" type="checkbox" id="thumbnail_crop" value="1" <?php checked('1', get_option('thumbnail_crop')); ?>/>
    <label for="thumbnail_crop"><?php _e('Crop thumbnail to exact dimensions (normally thumbnails are proportional)'); ?></label>

    Any idea how to remove it without fiddling with options-media.php?

    Thread Starter morgyface

    (@morgyface)

    Thanks for your help on this @bcworkz I can how what you’re proposing would work, but my ideal solution would be to add a checkbox to the settings/media page that simply updates the medium_crop option. Nice and clean.

    Thread Starter morgyface

    (@morgyface)

    I’m getting further with this, looks like add_settings_field is the way to go. My main issue is working out how to position the new crop checkbox. I can’t see how to specify where the checkbox appears on the settings page?

    Thread Starter morgyface

    (@morgyface)

    I’m now thinking one possible solution would be to add an additional checkbox underneath the Medium dimensions in the dashboard, replicating the layout of Thumbnail where there’s an option to “Crop thumbnail to exact dimensions”. Does anyone know how we could combine the above code with what I’m proposing here?

    Ahh okay.. I misunderstood. Let’s try this:

    <?php
    $args = array(
      'taxonomy' => 'campaigns'
    );
    $taxonomies = get_categories( $args );
    if ( $taxonomies ) {
      echo '<select name="select" id="campaigns">';
      foreach ( $taxonomies as $taxonomy ) {
          $name = $taxonomy->name;
          echo '<option value="' . $name . '">' . $name . '</option>';
      }
      echo '</select>';
    }
    ?>
Viewing 15 replies - 1 through 15 (of 48 total)