WordPress.org

Make WordPress Core

Ticket #15989: test_crop_filter.php

File test_crop_filter.php, 2.9 KB (added by buzz_matt, 3 years ago)

Exercises media.php patch

Line 
1<?php
2/**
3 * @package Test_Crop_Filter
4 * @version 0.01
5 */
6/*
7Plugin Name: Test Cropping Filter
8Plugin URI: http://buzz-media.com
9Description: Plugin to exercise the proposed image resizing crop filter
10Author: Matt White
11Version: 0.1
12Author URI: http://buzz-media.com
13*/
14
15//
16// FILTER BEING USED
17//
18
19add_filter('image_crop_location','buzzmedia_crop_control',10,6); // image_crop_area is not in core wp, you need to patch media.php
20function buzzmedia_crop_control ($orig_w,$orig_h,$crop_w,$crop_h,$s_x,$s_y)
21{
22        if (!($options=get_option('bm_crop_control'))) return array($s_x,$s_y);
23       
24       
25        switch ($options['crop_control']) {
26                case 'left_top';
27                        $s_x = 0;
28                        $s_y = 0;
29                break;
30               
31                case 'center_top';
32                        $s_y = 0;
33                break;
34               
35                case 'center_middle';
36                        // wordpress default - leave it be
37                break;
38        }
39        return array($s_x,$s_y); // return the coordinates of the top left hand corner of the crop
40               
41}
42
43
44
45
46//
47// JUST SOME ADMIN TO ALLOW US TO CONFIGURE THE TEST FILTER
48//
49
50
51add_action('admin_menu', 'buzzmedia_crop_menu');
52function buzzmedia_crop_menu() {
53        add_options_page('BM Crop Menu Options', 'BM Crop Control', 'manage_options', 'buzzmedia-crop-control', 'buzzmedia_crop_options');
54}
55
56
57add_action('admin_init','bm_crop_control_init');
58function bm_crop_control_init () {
59        register_setting('bm_crop_control_options','bm_crop_control');
60}
61
62
63function buzzmedia_crop_options() {
64        if (!current_user_can('manage_options'))  {
65                wp_die( __('You do not have sufficient permissions to access this page.') );
66        }
67        ?>
68        <div class="wrap">
69        <div id="icon-options-general" class="icon32"><br /></div>
70        <h2>BM Crop Control Settings</h2>
71        <p>This plugin exists only as a way to test the proposed image_crop_location filter added to media.php.</p>
72        <p>If you haven't applied the patch in ticket #15989, then don't expect much to happen.</p>
73        <p>If you <i>have</i> applied the patch <i>and</i> you have hard cropping selected in media settings, you can test as follows</p>
74        <p>
75                <ol>
76                        <li>Choose how you would like your image to be cropped from the dropdown in this page</li>
77                        <li>Save :)</li>
78                        <li>Edit a post and upload images (probably want to try some wide, long, and square variants</li>
79                        <li>Put a gallery shortcode in the post</li>
80                        <li>Save, then view the post - marvel at the thumbnails</li>
81                        <li>Come back to this page, change the settings - rinse and repeat til happy</li>
82                </ol>
83        </p>
84       
85        <form method="post" action="options.php">
86        <?php settings_fields('bm_crop_control_options'); ?>
87    <?php $options = get_option('bm_crop_control'); ?>
88    <p><b>Current Setting:<?=$options['crop_control']?></b></p>
89       
90        <b>Crop Location:</b>&nbsp;
91        <select name="bm_crop_control[crop_control]">
92                <option value="left_top">Left Top</option>
93                <option value="center_top">Center Top</option>
94                <option value="center_middle">Center Middle (wp default)</option>       
95        </select>
96        <p class="submit"><input type="submit" name="submit" id="submit" class="button-primary" value="Save Changes"  /></p>
97        </div>
98        <?php   
99}