resmushit-image-optimizer
Last commit date
classes
9 years ago
css
9 years ago
images
9 years ago
js
9 years ago
languages
9 years ago
readme.txt
9 years ago
resmushit.admin.php
9 years ago
resmushit.inc.php
9 years ago
resmushit.php
9 years ago
resmushit.settings.php
9 years ago
resmushit.admin.php
124 lines
| 1 | <?php |
| 2 | /** |
| 3 | * |
| 4 | * Create menu entries and routing |
| 5 | * |
| 6 | * @param none |
| 7 | * @return none |
| 8 | */ |
| 9 | function resmushit_create_menu() { |
| 10 | if ( is_super_admin() ) |
| 11 | add_media_page( 'reSmush.it', 'reSmush.it', 'manage_options', 'resmushit_options', 'resmushit_settings_page'); |
| 12 | } |
| 13 | add_action( 'admin_menu','resmushit_create_menu'); |
| 14 | |
| 15 | |
| 16 | |
| 17 | |
| 18 | |
| 19 | /** |
| 20 | * |
| 21 | * Declares settings entries |
| 22 | * |
| 23 | * @param none |
| 24 | * @return none |
| 25 | */ |
| 26 | function resmushit_settings_declare() { |
| 27 | register_setting( 'resmushit-settings', 'resmushit_on_upload' ); |
| 28 | register_setting( 'resmushit-settings', 'resmushit_qlty' ); |
| 29 | register_setting( 'resmushit-settings', 'resmushit_statistics' ); |
| 30 | register_setting( 'resmushit-settings', 'resmushit_logs' ); |
| 31 | } |
| 32 | add_action( 'admin_init', 'resmushit_settings_declare' ); |
| 33 | |
| 34 | |
| 35 | |
| 36 | function resmushit_media_list_add_column( $columns ) { |
| 37 | $columns["resmushit_disable"] = __('Disable of reSmush.it', 'resmushit'); |
| 38 | $columns["resmushit_status"] = __('reSmush.it status', 'resmushit'); |
| 39 | return $columns; |
| 40 | } |
| 41 | add_filter( 'manage_media_columns', 'resmushit_media_list_add_column' ); |
| 42 | |
| 43 | |
| 44 | function resmushit_media_list_sort_column( $columns ) { |
| 45 | $columns["resmushit_disable"] = "resmushit_disable"; |
| 46 | $columns["resmushit_status"] = "resmushit_status"; |
| 47 | return $columns; |
| 48 | } |
| 49 | add_filter( 'manage_upload_sortable_columns', 'resmushit_media_list_sort_column' ); |
| 50 | |
| 51 | |
| 52 | function resmushit_media_list_add_column_value( $column_name, $id ) { |
| 53 | if ( $column_name == "resmushit_disable" ) |
| 54 | reSmushitUI::mediaListCustomValuesDisable($id); |
| 55 | else if ( $column_name == "resmushit_status" ) |
| 56 | reSmushitUI::mediaListCustomValuesStatus($id); |
| 57 | } |
| 58 | add_action( 'manage_media_custom_column', 'resmushit_media_list_add_column_value', 10, 2 ); |
| 59 | |
| 60 | |
| 61 | /* Add custom field to attachment */ |
| 62 | function resmushit_image_attachment_add_status_button($form_fields, $post) { |
| 63 | $form_fields["rsmt-disabled-checkbox"] = array( |
| 64 | "label" => __("Disable of reSmush.it"), |
| 65 | "input" => "html", |
| 66 | "value" => '', |
| 67 | "html" => reSmushitUI::mediaListCustomValuesDisable($post->ID, true) |
| 68 | ); |
| 69 | |
| 70 | $form_fields["rsmt-status-button"] = array( |
| 71 | "label" => __("reSmush.it status"), |
| 72 | "input" => "html", |
| 73 | "value" => '', |
| 74 | "html" => reSmushitUI::mediaListCustomValuesStatus($post->ID, true) |
| 75 | ); |
| 76 | return $form_fields; |
| 77 | } |
| 78 | add_filter("attachment_fields_to_edit", "resmushit_image_attachment_add_status_button", null, 2); |
| 79 | |
| 80 | |
| 81 | |
| 82 | /** |
| 83 | * |
| 84 | * Settings page builder |
| 85 | * |
| 86 | * @param none |
| 87 | * @return none |
| 88 | */ |
| 89 | function resmushit_settings_page() { |
| 90 | ?> |
| 91 | <div class='rsmt-panels'> |
| 92 | <div class="rsmt-cols w66 iln-block"> |
| 93 | <?php reSmushitUI::headerPanel();?> |
| 94 | <?php reSmushitUI::bulkPanel();?> |
| 95 | <?php reSmushitUI::bigFilesPanel();?> |
| 96 | <?php reSmushitUI::statisticsPanel();?> |
| 97 | </div> |
| 98 | <div class="rsmt-cols w33 iln-block"> |
| 99 | <?php reSmushitUI::settingsPanel();?> |
| 100 | <?php reSmushitUI::newsPanel();?> |
| 101 | </div> |
| 102 | </div> |
| 103 | <?php |
| 104 | } |
| 105 | |
| 106 | |
| 107 | |
| 108 | /** |
| 109 | * |
| 110 | * Assets declaration |
| 111 | * |
| 112 | * @param none |
| 113 | * @return none |
| 114 | */ |
| 115 | function resmushit_register_plugin_assets(){ |
| 116 | |
| 117 | wp_register_style( 'resmushit-css', plugins_url( 'css/resmushit.css', __FILE__ ) ); |
| 118 | wp_enqueue_style( 'resmushit-css' ); |
| 119 | wp_enqueue_style( 'prefix-style', esc_url_raw( 'https://fonts.googleapis.com/css?family=Roboto+Slab:700' ), array(), null ); |
| 120 | |
| 121 | wp_register_script( 'resmushit-js', plugins_url( 'js/script.js', __FILE__ ) ); |
| 122 | wp_enqueue_script( 'resmushit-js' ); |
| 123 | } |
| 124 | add_action( 'admin_head', 'resmushit_register_plugin_assets' ); |