post_type)) {
return;
}
wp_nonce_field('taxopress_post_settings', 'taxopress_post_settings_nonce');
// Auto terms for this CPT ?
if (1 === (int) SimpleTags_Plugin::get_option_value('active_auto_terms')) {
$meta_value = self::get_status($post->ID, '_taxopress_autoterms_status', '_exclude_autotags');
echo '
' . "\n";
echo '
' . "\n";
echo '' . "\n";
echo '
' . "\n";
echo '';
}
if (1 === (int) SimpleTags_Plugin::get_option_value('active_auto_links')) {
$meta_value = self::get_status($post->ID, '_taxopress_autolinks_status', '_exclude_autolinks');
echo '' . "\n";
echo '
' . "\n";
echo '' . "\n";
echo '
' . "\n";
echo '';
}
}
/**
* Save this settings in post meta, delete if no exclude, clean DB :)
*
* @param integer $object_id
*
* @return void
* @author WebFactory Ltd
*/
public static function save_post($object_id = 0)
{
if (
! isset($_POST['taxopress_post_settings_nonce'])
|| ! wp_verify_nonce(
sanitize_text_field(wp_unslash($_POST['taxopress_post_settings_nonce'])),
'taxopress_post_settings'
)
) {
return;
}
if ((defined('DOING_AUTOSAVE') && DOING_AUTOSAVE) || wp_is_post_revision($object_id)) {
return;
}
if (! current_user_can('edit_post', $object_id)) {
return;
}
$has_autotags_meta = isset($_POST['_meta_autotags']) && 'true' === sanitize_text_field(wp_unslash($_POST['_meta_autotags']));
$has_autolink_meta = isset($_POST['_meta_autolink']) && 'true' === sanitize_text_field(wp_unslash($_POST['_meta_autolink']));
if ($has_autotags_meta) {
self::save_status($object_id, 'taxopress_autoterms_status', '_taxopress_autoterms_status', '_exclude_autotags');
}
if ($has_autolink_meta) {
self::save_status($object_id, 'taxopress_autolinks_status', '_taxopress_autolinks_status', '_exclude_autolinks');
}
}
private static function get_status($post_id, $status_meta_key, $legacy_disable_meta_key = '')
{
$status = get_post_meta($post_id, $status_meta_key, true);
if (self::is_valid_status($status)) {
return $status;
}
if ($legacy_disable_meta_key && get_post_meta($post_id, $legacy_disable_meta_key, true)) {
return self::STATUS_DISABLED;
}
return self::STATUS_DEFAULT;
}
private static function save_status($post_id, $post_key, $status_meta_key, $legacy_disable_meta_key = '')
{
$status = isset($_POST[$post_key]) ? sanitize_key(wp_unslash($_POST[$post_key])) : self::STATUS_DEFAULT;
if (! self::is_valid_status($status)) {
$status = self::STATUS_DEFAULT;
}
if (self::STATUS_DEFAULT === $status) {
delete_post_meta($post_id, $status_meta_key);
} else {
update_post_meta($post_id, $status_meta_key, $status);
}
if ($legacy_disable_meta_key) {
if (self::STATUS_DISABLED === $status) {
update_post_meta($post_id, $legacy_disable_meta_key, true);
} else {
delete_post_meta($post_id, $legacy_disable_meta_key);
}
}
}
private static function status_options($current_status)
{
$statuses = [
self::STATUS_DEFAULT => esc_html__('Default', 'simple-tags'),
self::STATUS_ENABLED => esc_html__('Enable', 'simple-tags'),
self::STATUS_DISABLED => esc_html__('Disable', 'simple-tags'),
];
foreach ($statuses as $status => $label) {
echo '' . "\n";
}
}
private static function is_valid_status($status)
{
return in_array($status, [self::STATUS_DEFAULT, self::STATUS_ENABLED, self::STATUS_DISABLED], true);
}
}