-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathritmo.php
More file actions
181 lines (150 loc) · 4.59 KB
/
ritmo.php
File metadata and controls
181 lines (150 loc) · 4.59 KB
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
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
<?php
/*
Plugin Name: Ritmo
Plugin URI: https://wordpress.org/plugins/ritmo
Description: Ritmo player for wordpress
Author: Mostafa Soufi
Version: 1.0
Author URI: http://mostafa-soufi.ir
Text Domain: ritmo
*/
define('WP_RITMO_DIR', plugin_dir_url(__FILE__));
load_plugin_textdomain('ritmo', false, dirname( plugin_basename( __FILE__ ) ) . '/languages');
class Ritmo{
/**
* Constructors plugin
*
* @param Not param
*/
public function __construct() {
// Translate plugin name
__('Ritmo', 'auto-slug-cleaner');
__('Ritmo player for wordpress', 'auto-slug-cleaner');
// Include files
$this->includes();
// Init setting
$this->setting();
add_shortcode( 'ritmo', array($this, 'shortcode') );
// Register meta box
if ( is_admin() ) {
add_action( 'add_meta_boxes', array( $this, 'add_meta_box' ) );
add_action( 'save_post', array( $this, 'save_meta_box') );
}
}
/**
* Includes plugin files
*
* @param Not param
*/
public function includes() {
$files = array(
'widget',
'includes/functions',
);
foreach($files as $file) {
include_once dirname( __FILE__ ) . '/' . $file . '.php';
}
}
/**
* Setting plugin
*
* @param Not param
*/
public function setting() {
require_once( 'includes/settings.php' );
global $ritmo_settings;
$ritmo_settings = ritmo_get_settings();
}
/**
* Adds the meta box container.
*/
public function add_meta_box( $post_type ) {
global $ritmo_settings;
// Get post type
foreach ($ritmo_settings as $field => $index) {
if( $field = 'post_type-'.$field ) {
$post_types[] = str_replace('post_type-', '', $field);
}
}
if ( in_array( $post_type, $post_types ) ) {
add_meta_box(
'ritmo_meta_box_name',
__( 'Ritmo', 'ritmo' ),
array( $this, 'render_meta_box_content' ),
$post_type,
'advanced',
'high'
);
}
}
/**
* Save the meta when the post is saved.
*
* @param int $post_id The ID of the post being saved.
*/
public function save_meta_box( $post_id ) {
// Check if ritmo url us set
if ( empty( $_POST['ritmo_url'] ) ) {
return $post_id;
}
// Check if nonce is set.
if ( ! isset( $_POST['ritmo_inner_nonce'] ) ) {
return $post_id;
}
$nonce = $_POST['ritmo_inner_nonce'];
// Verify that the nonce is valid.
if ( ! wp_verify_nonce( $nonce, 'ritmo' ) ) {
return $post_id;
}
/*
* If this is an autosave, form has not been submitted,
* so we don't want to do anything.
*/
if ( defined( 'DOING_AUTOSAVE' ) && DOING_AUTOSAVE ) {
return $post_id;
}
// Check the user's permissions.
if ( 'page' == $_POST['post_type'] ) {
if ( ! current_user_can( 'edit_page', $post_id ) ) {
return $post_id;
}
} else {
if ( ! current_user_can( 'edit_post', $post_id ) ) {
return $post_id;
}
}
/* OK, it's safe for us to save the data now. */
// Sanitize the user input.
$data = $_POST['ritmo_url'];
// Update the meta field.
update_post_meta( $post_id, 'ritmo_url', $data );
}
/**
* Render Meta Box content.
*
* @param WP_Post $post The post object.
*/
public function render_meta_box_content( $post ) {
// Add an nonce field so we can check for it later.
wp_nonce_field( 'ritmo', 'ritmo_inner_nonce' );
// Use get_post_meta to retrieve an existing value from the database.
$value = get_post_meta( $post->ID, 'ritmo_url', true );
// Display the form, using the current value.
?>
<label for="ritmo_url">
<?php _e( 'Enter Ritmo url', 'ritmo' ); ?>
</label>
<p><input type="text" id="ritmo_url" name="ritmo_url" value="<?php echo esc_attr( $value ); ?>" style="width:100%" dir="ltr" /></p>
<?php
}
/**
* Create shortcode for show embeded in post/page or text widget
*
* @param Not param
*/
public function shortcode() {
return ritmo();
}
}
// Create object of plugin
$Ritmo = new Ritmo;