PluginProbe
Thumbnail Editor / trunk
Thumbnail Editor vtrunk
trunk 1.0.0 1.1.0 1.2.0 2.0.0 2.0.1 2.1.1 2.1.2 2.2.0 2.2.1 2.2.2 2.2.3 2.2.4 2.2.5 2.2.6 2.2.7 2.2.8 2.2.9 2.3.0 2.3.1 2.3.2 2.3.3 2.3.4
thumbnail-editor / includes / class-settings.php

class-settings.php in Thumbnail Editor trunk, at includes/class-settings.php

135 lines 4.2 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class Thumbnail_Settings {
4
5 public function __construct() {
6 add_action( 'admin_menu', array( $this, 'admin_menu' ) );
7 add_filter( 'media_row_actions', array( $this, 'media_row_actions' ), 10, 3);
8 add_filter( 'attachment_fields_to_edit', array( $this, 'media_thumbnail_edit_link' ), 10, 20 );
9 }
10
11 public function media_row_actions($actions, $post, $detached){
12 $actions['thued'] = '<a href="options-general.php?page=thumbnail_editor_setup_data&att_id='.$post->ID.'" title="Crop Thumbnail">'.__('Crop Thumbnail','thumbnail-editor').'</a>';
13 return $actions;
14 }
15
16 public function media_thumbnail_edit_link( $form_fields, $post ) {
17 $hide_info = '<style>.media-types-required-info{display:none;}</style>';
18
19 $form_fields['th-editor-link'] = array(
20 'label' => '',
21 'input' => 'html',
22 'html' => '<a href="options-general.php?page=thumbnail_editor_setup_data&att_id='.$post->ID.'" title="Crop Thumbnail" class="button">'.__('Crop Thumbnail','thumbnail-editor').'</a>' . $hide_info,
23 );
24
25 return $form_fields;
26 }
27
28 public function admin_menu () {
29 add_options_page( 'Thumbnail Editor','Thumbnail Editor','manage_options','thumbnail_editor_setup_data', array( $this, 'view' ) );
30 }
31
32 public function view(){
33 $att_id = '';
34 if(isset($_REQUEST['att_id'])){
35 $att_id = (int)sanitize_text_field($_REQUEST['att_id']);
36 }
37 if($att_id == 0 || $att_id == ''){
38 $this->settings();
39 } else {
40 $this->editor($att_id);
41 }
42 }
43
44 public function show_message(){
45 if(isset($GLOBALS['msg']) and $GLOBALS['msg'] != ''){
46 echo '<div class="updated notice notice-success"><p>'.$GLOBALS['msg'].'</p></div>';
47 unset($GLOBALS['msg']);
48 }
49 }
50
51 public function settings() {
52 $thep_disable_srcset = get_option('thep_disable_srcset');
53 $thep_disable_wh = get_option('thep_disable_wh');
54
55 echo '<div class="wrap">';
56 $this->show_message();
57 $this->help_support();
58 include( THE_PLUGIN_PATH . '/view/admin/settings.php');
59 $this->thumbnail_editor_pro_add();
60 $this->donate();
61 echo '</div>';
62
63 }
64
65 public function editor() {
66 echo '<div class="wrap">';
67 $att_id = '';
68
69 $this->show_message();
70 $this->help_support();
71
72 if(isset($_REQUEST['att_id'])){
73 $att_id = sanitize_text_field($_REQUEST['att_id']);
74 }
75
76 if($att_id == ''){
77 echo '<p>Goto <a href="upload.php"><strong>Media Library</strong></a> and select <strong>Crop Thumbnail</strong> link to modify image thumbnails.</p>';
78 return;
79 }
80
81 $full_image = wp_get_attachment_image_src( $att_id, 'full' );
82
83 if($full_image == ''){
84 echo '<p>Please select an <strong>Image</strong> file to edit. Go back to <a href="upload.php"><strong>Media Library</strong></a></p>';
85 return;
86 }
87
88 include( THE_PLUGIN_PATH . '/view/admin/editor-settings.php');
89
90 $this->donate();
91 echo '<div>';
92 }
93
94
95 public function help_support(){
96 include( THE_PLUGIN_PATH . '/view/admin/help.php');
97 }
98
99 public function donate(){
100 include( THE_PLUGIN_PATH . '/view/admin/donate.php');
101 }
102
103 public function thumbnail_editor_pro_add(){
104 include( THE_PLUGIN_PATH . '/view/admin/pro-add.php');
105 }
106
107 public function get_image_sizes( $size = '' ) {
108 global $_wp_additional_image_sizes;
109 $sizes = array();
110 $get_intermediate_image_sizes = get_intermediate_image_sizes();
111 // Create the full array with sizes and crop info
112 foreach( $get_intermediate_image_sizes as $_size ) {
113 if ( in_array( $_size, array( 'thumbnail', 'medium', 'large' ) ) ) {
114 $sizes[ $_size ]['width'] = get_option( $_size . '_size_w' );
115 $sizes[ $_size ]['height'] = get_option( $_size . '_size_h' );
116 $sizes[ $_size ]['crop'] = (bool) get_option( $_size . '_crop' );
117
118 } elseif ( isset( $_wp_additional_image_sizes[ $_size ] ) ) {
119 $sizes[ $_size ] = array(
120 'width' => $_wp_additional_image_sizes[ $_size ]['width'],
121 'height' => $_wp_additional_image_sizes[ $_size ]['height'],
122 'crop' => $_wp_additional_image_sizes[ $_size ]['crop']
123 );
124 }
125 }
126 if ( $size ) {
127 if( isset( $sizes[ $size ] ) ) {
128 return $sizes[ $size ];
129 } else {
130 return false;
131 }
132 }
133 return $sizes;
134 }
135 }