* @copyright (c) 2013, OnePress Ltd * * @package core * @since 1.0.0 */ /** * The class to show info on how the plugin support is provided. * * @since 1.0.0 */ class OPanda_BulkLockingMetaBox extends FactoryMetaboxes321_Metabox { /** * A visible title of the metabox. * * Inherited from the class FactoryMetabox. * @link http://codex.wordpress.org/Function_Reference/add_meta_box * * @since 1.0.0 * @var string */ public $title; /** * The priority within the context where the boxes should show ('high', 'core', 'default' or 'low'). * * @link http://codex.wordpress.org/Function_Reference/add_meta_box * Inherited from the class FactoryMetabox. * * @since 1.0.0 * @var string */ public $priority = 'core'; /** * The part of the page where the edit screen section should be shown ('normal', 'advanced', or 'side'). * * @link http://codex.wordpress.org/Function_Reference/add_meta_box * Inherited from the class FactoryMetabox. * * @since 1.0.0 * @var string */ public $context = 'side'; public function __construct( $plugin ) { parent::__construct( $plugin ); $this->title = __('Batch Locking', 'bizpanda'); } public function configure( $scripts, $styles ){ $scripts->add( OPANDA_BIZPANDA_URL . '/assets/admin/js/metaboxes/bulk-lock.010000.js'); } /** * Renders content of the metabox. * * @see FactoryMetaboxes321_Metabox * @since 1.0.0 * * @return void */ public function html() { global $post; $options = get_post_meta($post->ID, 'opanda_bulk_locking', true); // current bulk locker for the "skip & lock" and "more tag" modes $bulkLockerId = intval( get_option('onp_sl_bulk_locker', 0) ); $bulkLocker = null; if ( $bulkLockerId !== 0 && $bulkLockerId != $post->ID ) { $bulkLocker = get_post($bulkLockerId); if ( $bulkLocker && empty( $bulkLocker->post_title ) ) $bulkLocker->post_title = __('No title', 'bizpanda'); } // gets values for the form $setupStateClass = empty( $options ) ? 'onp-sl-empty-state' : 'onp-sl-has-options-state'; $wayStateClass = ''; if ( !empty($options) && isset( $options['way'] ) ) { if ( $options['way'] == 'skip-lock' ) $wayStateClass = 'onp-sl-skip-lock-state'; elseif ( $options['way'] == 'more-tag' ) $wayStateClass = 'onp-sl-more-tag-state'; elseif ( $options['way'] == 'css-selector' ) $wayStateClass = 'onp-sl-css-selector-state'; } $skipAndLockStateClass = ''; if ( !empty($options) && $options['way'] == 'skip-lock' ) { if ( $options['skip_number'] == 0 ) $skipAndLockStateClass = 'onp-sl-skip-lock-0-state'; elseif ( $options['skip_number'] == 1 ) $skipAndLockStateClass = 'onp-sl-skip-lock-1-state'; elseif ( $options['skip_number'] > 1 ) $skipAndLockStateClass = 'onp-sl-skip-lock-2-state'; } $ruleStateClass = ''; $defaultWay = 'skip-lock'; if ( !empty($options) ) $defaultWay = $options['way']; $skipNumber = 1; if ( !empty($options) && $options['way'] == 'skip-lock' ) { $skipNumber = intval( $options['skip_number'] ); } $cssSelector = ''; if ( !empty($options) && $options['way'] == 'css-selector' ) { $cssSelector = urldecode( $options['css_selector'] ); } $excludePosts = ''; if ( !empty($options) && !empty( $options['exclude_posts'] ) ) { $excludePosts = implode(', ', $options['exclude_posts']); $ruleStateClass .= ' onp-sl-exclude-post-ids-rule-state'; } $excludeCategories = ''; if ( !empty($options) && !empty( $options['exclude_categories'] ) ) { $excludeCategories = implode(', ', $options['exclude_categories']); $ruleStateClass .= ' onp-sl-exclude-categories-ids-rule-state'; } $postTypes = ''; if ( !empty($options) && !empty( $options['post_types'] ) ) { $postTypes = implode(', ', $options['post_types'] ); $ruleStateClass .= ' onp-sl-post-types-rule-state'; } $checkedPostTypes = array('post', 'page'); if ( !empty($options) && !empty( $options['post_types'] ) ) { $checkedPostTypes = $options['post_types']; } $types = get_post_types( array('public' => true), 'objects' ); // get interrelated option $interrelated = get_option('opanda_interrelation', false); $interrelatedClass = ( !$interrelated ) ? 'onp-sl-not-interrelation' : ''; ?>
$optionValue ) { ?>
Common Settings page. It allows to unlock all lockers when one is unlocked.', 'bizpanda'), opanda_get_admin_url("settings", array( 'opanda_screen' => 'lock' ) ) ) ?>
way; return $classes; } public function save( $postId ) { // clear previos settings $bulkLockers = get_option('onp_sl_bulk_lockers', array()); if ( !is_array($bulkLockers) ) $bulkLockers = array(); if ( isset( $bulkLockers[$postId] ) ) unset( $bulkLockers[$postId] ); if ( !isset( $_POST['onp_sl_way'] ) ) { delete_post_meta($postId, 'opanda_bulk_locking'); delete_option('onp_sl_bulk_lockers'); add_option('onp_sl_bulk_lockers', $bulkLockers); return; } else { $way = $_POST['onp_sl_way']; if ( !in_array( $way, array( 'skip-lock', 'more-tag', 'css-selector' )) ) { delete_post_meta($postId, 'opanda_bulk_locking'); delete_option('onp_sl_bulk_lockers'); add_option('onp_sl_bulk_lockers', $bulkLockers); return; } $data = array('way' => $way); if ( $way == 'skip-lock' ) { $data['skip_number'] = intval( $_POST['onp_sl_skip_number'] ); } elseif( $way == 'css-selector' ) { $data['css_selector'] = $_POST['onp_sl_css_selector']; } if ( $way == 'skip-lock' || $way == 'more-tag' ) { $postTypes = isset( $_POST['onp_sl_post_types'] ) ? $_POST['onp_sl_post_types'] : ''; $excludePosts = isset( $_POST['onp_sl_exclude_posts'] ) ? $_POST['onp_sl_exclude_posts'] : ''; $excludeCategories = isset( $_POST['onp_sl_exclude_categories'] ) ? $_POST['onp_sl_exclude_categories'] : ''; $data['post_types'] = explode ( ',', $postTypes ); $data['post_types'] = !empty( $data['post_types'] ) ? array_map( 'trim', $data['post_types'] ) : array(); $data['exclude_posts'] = !empty( $excludePosts ) ? $this->_normalizeIntValArray( explode ( ',', $excludePosts ) ) : array(); $data['exclude_categories'] = !empty( $excludeCategories ) ? $this->_normalizeIntValArray( explode ( ',', $excludeCategories ) ) : array(); } $bulkLockers[$postId] = $data; delete_option('onp_sl_bulk_lockers'); add_option('onp_sl_bulk_lockers', $bulkLockers); update_post_meta($postId, 'opanda_bulk_locking', $data); } } function _normalizeIntValArray( $arr ) { $arr = !empty( $arr ) ? array_map( 'intval', $arr ) : array(); $return = array(); foreach( $arr as $value ) { if ( $value == 0 ) continue; $return[] = $value; } return $return; } } global $bizpanda; FactoryMetaboxes321::register('OPanda_BulkLockingMetaBox', $bizpanda);