-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathshortcode-enablr.php
More file actions
61 lines (49 loc) · 1.95 KB
/
shortcode-enablr.php
File metadata and controls
61 lines (49 loc) · 1.95 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
<?php
/**
* Plugin Name: Shortcode Enablr
* Plugin URI: https://github.com/herdl/shortcode-enablr
* Description: Shortcode enabler.
* Author: Herdl
* Version: 1.1.4
* Author URI: https://herdl.com
*/
if (!defined('WPINC')) {
die('No direct access allowed');
}
function shortcode_enablr_register_settings() {
add_submenu_page('options-general.php', 'Shortcode Enablr', 'Shortcode Enablr', 'manage_options', 'shortcode_enablr', 'shortcode_enablr_settings');
}
function shortcode_enablr_settings() {
if (!current_user_can('administrator')) {
echo '<p>Sorry, you are not allowed to access this page.</p>';
return;
}
if (isset($_REQUEST['submit'])) {
if (!isset($_REQUEST['shortcode_enablr_nonce'])) {
$errorMessage = 'nonce field is missing. Settings NOT saved.';
} elseif (!wp_verify_nonce($_REQUEST['shortcode_enablr_nonce'], 'shortcode_enablr')) {
$errorMessage = 'Invalid nonce specified. Settings NOT saved.';
} else {
update_option('shortcode_enablr_acf_enable', isset($_REQUEST['shortcode_enablr_acf_enable']) ? 'yes' : 'no');
update_option('shortcode_enablr_yoast_title_enable', isset($_REQUEST['shortcode_enablr_yoast_title_enable']) ? 'yes' : 'no');
$message = 'Settings Saved.';
}
}
include_once(__DIR__ . '/templates/settings.php');
}
if (get_option('shortcode_enablr_acf_enable') === 'yes') {
add_filter('acf/format_value', 'shortcode_enablr_acf_format_value', 10, 3);
function shortcode_enablr_acf_format_value($value, $post_id, $field) {
if (!is_array($value)) {
return do_shortcode($value);
}
}
}
if (get_option('shortcode_enablr_yoast_title_enable') === 'yes') {
add_filter('wpseo_title', 'shortcode_enablr_wpseo_title');
function shortcode_enablr_wpseo_title($title)
{
return do_shortcode($title);
}
}
add_action('admin_menu', 'shortcode_enablr_register_settings');