forked from thomasgriffin/New-Media-Image-Uploader
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathtgm-new-media-plugin.php
119 lines (96 loc) · 4.26 KB
/
tgm-new-media-plugin.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
<?php
/*
Plugin Name: TGM New Media Plugin
Plugin URI: http://thomasgriffinmedia.com/
Description: This plugin gives an example of how to customize the new media manager experience in WordPress 3.5.
Author: Thomas Griffin
Author URI: http://thomasgriffinmedia.com/
Version: 1.0.0
License: GNU General Public License v2.0 or later
License URI: http://www.opensource.org/licenses/gpl-license.php
*/
/*
Copyright 2013 Thomas Griffin (email : thomas@thomasgriffinmedia.com)
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License, version 2, as
published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/
/**
* Main class for the plugin.
*
* @since 1.0.0
*
* @package TGM New Media Plugin
* @author Thomas Griffin
*/
class TGM_New_Media_Plugin {
/**
* Constructor for the class.
*
* @since 1.0.0
*/
public function __construct() {
// Load the plugin textdomain.
load_plugin_textdomain( 'tgm-nmp', false, dirname( plugin_basename( __FILE__ ) ) . '/languages/' );
// Load our custom assets.
add_action( 'admin_enqueue_scripts', array( $this, 'assets' ) );
// Generate the custom metabox to hold our example media manager.
add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );
}
/**
* Loads any plugin assets we may have.
*
* @since 1.0.0
*
* @return null Return early if not on a page add/edit screen
*/
public function assets() {
// Bail out early if we are not on a page add/edit screen.
if ( ! ( 'post' == get_current_screen()->base && 'page' == get_current_screen()->id ) )
return;
// This function loads in the required media files for the media manager.
wp_enqueue_media();
// Register, localize and enqueue our custom JS.
wp_register_script( 'tgm-nmp-media', plugins_url( '/js/media.js', __FILE__ ), array( 'jquery' ), '1.0.0', true );
wp_localize_script( 'tgm-nmp-media', 'tgm_nmp_media',
array(
'title' => __( 'Upload or Choose Your Custom Image File', 'tgm-nmp' ), // This will be used as the default title
'button' => __( 'Insert Image into Input Field', 'tgm-nmp' ) // This will be used as the default button text
)
);
wp_enqueue_script( 'tgm-nmp-media' );
}
/**
* Create the custom metabox.
*
* @since 1.0.0
*/
public function add_meta_boxes() {
// This metabox will only be loaded for pages.
add_meta_box( 'tgm-new-media-plugin', __( 'TGM New Media Plugin Settings', 'tgm-nmp' ), array( $this, 'metabox' ), 'page', 'normal', 'high' );
}
/**
* Callback function to output our custom settings page.
*
* @since 1.0.0
*
* @param object $post Current post object data
*/
public function metabox( $post ) {
echo '<div id="tgm-new-media-settings">';
echo '<p>' . __( 'Click on the button below to open up the media modal and watch your customizations come to life!', 'tgm-nmp' ) . '</p>';
echo '<p><strong>' . __( 'Please note that none of this will save when you update the page. This is just for demonstration purposes only!', 'tgm-nmp' ) . '</strong></p>';
echo '<p><a href="#" class="tgm-open-media button button-primary" title="' . esc_attr__( 'Click Here to Open the Media Manager', 'tgm-nmp' ) . '">' . __( 'Click Here to Open the Media Manager', 'tgm-nmp' ) . '</a></p>';
echo '<p><label for="tgm-new-media-image">' . __( 'Our Image Goes Here!', 'tgm-nmp' ) . '</label> <input type="text" id="tgm-new-media-image" size="70" value="" /></p>';
echo '</div>';
}
}
// Instantiate the class.
$tgm_new_media_plugin = new TGM_New_Media_Plugin();