PluginProbe
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms / 3.50.0
Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms v3.50.0
3.54.0 3.53.0 3.52.0 3.51.0 3.50.0 3.45.0 3.38.0 3.4.0 3.4.1 3.4.2 3.4.3 3.4.4 3.4.5 3.40.0 3.40.1 3.41.0 3.42.0 3.43.0 3.44.0 3.5.0 3.5.1 3.5.2 3.5.3 3.6.0 3.6.1 All 178 releases
simple-tags / inc / class.admin.post.php

class.admin.post.php in Tag, Category, and Taxonomy Manager – Autotagger Automatically Add Terms 3.50.0, at inc/class.admin.post.php

106 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 <?php
2
3 class SimpleTags_Admin_Post_Settings
4 {
5 /**
6 * Constructor
7 *
8 * @return void
9 * @author WebFactory Ltd
10 */
11 public function __construct()
12 {
13
14 if ((1 === (int) SimpleTags_Plugin::get_option_value('active_auto_links')) || (1 === (int) SimpleTags_Plugin::get_option_value('active_auto_terms'))) {
15 // Save tags from advanced input
16 add_action('save_post', array( __CLASS__, 'save_post' ), 10, 1);
17 // Box for advanced tags
18 add_action('add_meta_boxes', array( __CLASS__, 'add_meta_boxes' ), 10, 1);
19 }
20 }
21
22 /**
23 * Register a new box for TaxoPress settings
24 *
25 * @param string $post_type
26 *
27 * @return void
28 * @author WebFactory Ltd
29 */
30 public static function add_meta_boxes($post_type)
31 {
32
33 $autoterm = taxopress_post_type_autoterms();
34 $autolink = taxopress_post_type_autolink_autolink();
35
36 if (!is_array($autoterm) && !is_array($autolink)) {
37 return;
38 }
39
40 // Auto terms for this CPT ?
41 add_meta_box('simpletags-settings', __('TaxoPress', 'simple-tags'), array(
42 __CLASS__,
43 'metabox'
44 ), $post_type, 'side', 'low');
45 }
46
47 /**
48 * Build HTML of form
49 *
50 * @param object $post
51 *
52 * @return void
53 * @author WebFactory Ltd
54 */
55 public static function metabox($post)
56 {
57 if (! isset($post->post_type)) {
58 return;
59 }
60
61 // Auto terms for this CPT ?
62 if (1 === (int) SimpleTags_Plugin::get_option_value('active_auto_terms')) {
63 $meta_value = get_post_meta($post->ID, '_exclude_autotags', true);
64 echo '<p>' . "\n";
65 echo '<label><input type="checkbox" name="exclude_autotags" value="true" ' . checked(esc_attr($meta_value), true, false) . ' /> ' . esc_html__('Disable Auto Terms', 'simple-tags') . '</label><br />' . "\n";
66 echo '</p>' . "\n";
67 echo '<input type="hidden" name="_meta_autotags" value="true" />';
68 }
69
70 if (1 === (int) SimpleTags_Plugin::get_option_value('active_auto_links')) {
71 $meta_value = get_post_meta($post->ID, '_exclude_autolinks', true);
72 echo '<p>' . "\n";
73 echo '<label><input type="checkbox" name="exclude_autolinks" value="true" ' . checked(esc_attr($meta_value), true, false) . ' /> ' . esc_html__('Disable Auto Links', 'simple-tags') . '</label><br />' . "\n";
74 echo '</p>' . "\n";
75 echo '<input type="hidden" name="_meta_autolink" value="true" />';
76 }
77 }
78
79 /**
80 * Save this settings in post meta, delete if no exclude, clean DB :)
81 *
82 * @param integer $object_id
83 *
84 * @return void
85 * @author WebFactory Ltd
86 */
87 public static function save_post($object_id = 0)
88 {
89 if (isset($_POST['_meta_autotags']) && 'true' === $_POST['_meta_autotags']) {
90 if (isset($_POST['exclude_autotags'])) {
91 update_post_meta($object_id, '_exclude_autotags', true);
92 } else {
93 delete_post_meta($object_id, '_exclude_autotags');
94 }
95 }
96
97 if (isset($_POST['_meta_autolink']) && 'true' === $_POST['_meta_autolink']) {
98 if (isset($_POST['exclude_autolinks'])) {
99 update_post_meta($object_id, '_exclude_autolinks', true);
100 } else {
101 delete_post_meta($object_id, '_exclude_autolinks');
102 }
103 }
104 }
105 }
106