action || 'post' !== $screen->base || OPANDA_POST_TYPE !== $screen->post_type ) return; if ( isset( $_GET['opanda_item'] ) ) return; global $bizpanda; $url = admin_url('edit.php?post_type=' . OPANDA_POST_TYPE . '&page=new-item-' . $bizpanda->pluginName ); wp_redirect( $url ); exit; } add_action('current_screen', 'opanda_redirect_to_new_item'); // --- // Editor // /** * Registers the BizPanda button for the TinyMCE * * @see mce_buttons * @since 1.0.0 */ function opanda_register_button($buttons) { if ( !current_user_can('edit_' . OPANDA_POST_TYPE) ) return $buttons; array_push($buttons, "optinpanda"); return $buttons; } add_filter('mce_buttons', 'opanda_register_button'); /** * Registers the BizPanda plugin for the TinyMCE * * @see mce_external_plugins * @since 1.0.0 */ function opanda_add_plugin($plugin_array) { if ( !current_user_can('edit_' . OPANDA_POST_TYPE) ) return $plugin_array; global $wp_version; if ( version_compare( $wp_version, '3.9', '<' ) ) { $plugin_array['optinpanda'] = OPANDA_BIZPANDA_URL . '/assets/admin/js/optinpanda.tinymce3.js'; } else { $plugin_array['optinpanda'] = OPANDA_BIZPANDA_URL . '/assets/admin/js/optinpanda.tinymce4.010.js'; } return $plugin_array; } add_filter('mce_external_plugins', 'opanda_add_plugin'); /** * Adds js variable required for shortcodes. * * @see before_wp_tiny_mce * @since 1.1.0 */ function opanda_tinymce_data() { // styles for the plugin shorcodes $shortcodeIcon = BizPanda::getShortCodeIcon(); $shortcodeTitle = strip_tags( BizPanda::getMenuTitle() ); ?> query_vars['meta_key'] = 'opanda_item'; $wp_query->query_vars['meta_value'] = OPanda_Items::getAvailableNames(); } add_action( 'pre_get_posts', 'opanda_filter_panda_items_in_view_table' ); require OPANDA_BIZPANDA_DIR . '/admin/includes/classes/class.lockers.viewtable.php'; } // --- // Post Row Actions // function opanda_clone_item() { if ( !isset($_GET['action']) || $_GET['action'] !== 'opanda-clone-item' ) return; if ( !isset($_GET['post_type']) || $_GET['post_type'] !== 'opanda-item' ) return; if ( !isset($_GET['_wpnonce'] ) ) return; if ( !wp_verify_nonce($_GET['_wpnonce'], 'opanda-clone-item-nonce') ) return; global $wpdb; $postId = (isset($_GET['post']) ? $_GET['post'] : $_POST['post']); $post = get_post($postId); if( isset($post) && $post != null ) { $currentUser = wp_get_current_user(); $postAuthor = $currentUser->ID; $args = array( 'comment_status' => $post->comment_status, 'ping_status' => $post->ping_status, 'post_author' => $postAuthor, 'post_content' => $post->post_content, 'post_excerpt' => $post->post_excerpt, 'post_name' => $post->post_name, 'post_parent' => $post->post_parent, 'post_password' => $post->post_password, 'post_status' => 'publish', 'post_title' => $post->post_title . " " . __('Copy', 'bizpanda'), 'post_type' => $post->post_type, 'to_ping' => $post->to_ping, 'menu_order' => $post->menu_order ); $newPostId = wp_insert_post($args); $sqlQuery = "INSERT INTO $wpdb->postmeta (post_id, meta_key, meta_value) SELECT $newPostId as post_id, meta_key, meta_value FROM $wpdb->postmeta WHERE post_id = {$postId}"; $wpdb->query($sqlQuery); update_post_meta($newPostId, 'opanda_is_system', false); update_post_meta($newPostId, 'opanda_is_default', false); update_post_meta($newPostId, 'opanda_imperessions', 0); update_post_meta($newPostId, 'opanda_unlocks', 0); $bulkLockers = get_option('onp_sl_bulk_lockers', array()); if( array_key_exists($postId, $bulkLockers) ) { $bulkLockers[$newPostId] = $bulkLockers[$postId]; update_option('onp_sl_bulk_lockers', $bulkLockers); } wp_redirect(admin_url('post.php?action=edit&post=' . $newPostId)); exit; } else { wp_die(__('Post creation failed, could not find original post!', 'opanda')); } } add_action('admin_init', 'opanda_clone_item'); // --- // Metaboxes // /** * Registers default options (lockers, popups, forms). * * @since 1.0.0 */ function opanda_add_meta_boxes() { global $bizpanda; $type = OPanda_Items::getCurrentItem(); if ( empty( $type ) ) return; $typeName = $type['name']; $data = array(); if ( OPanda_Items::isCurrentPremium() ) { $data[] = array( 'class' => 'OPanda_BasicOptionsMetaBox', 'path' => OPANDA_BIZPANDA_DIR . '/includes/metaboxes/basic-options.php' ); $data[] = array( 'class' => 'OPanda_PreviewMetaBox', 'path' => OPANDA_BIZPANDA_DIR . '/includes/metaboxes/preview.php' ); $data[] = array( 'class' => 'OPanda_ManualLockingMetaBox', 'path' => OPANDA_BIZPANDA_DIR . '/includes/metaboxes/manual-locking.php' ); $data[] = array( 'class' => 'OPanda_BulkLockingMetaBox', 'path' => OPANDA_BIZPANDA_DIR . '/includes/metaboxes/bulk-locking.php' ); $data[] = array( 'class' => 'OPanda_TermsOptionsMetaBox', 'path' => OPANDA_BIZPANDA_DIR . '/includes/metaboxes/terms-privacy.php' ); $data[] = array( 'class' => 'OPanda_VisabilityOptionsMetaBox', 'path' => OPANDA_BIZPANDA_DIR . '/includes/metaboxes/visability-options.php' ); $data[] = array( 'class' => 'OPanda_AdvancedOptionsMetaBox', 'path' => OPANDA_BIZPANDA_DIR . '/includes/metaboxes/advanced-options.php' ); } else { $data[] = array( 'class' => 'OPanda_BasicOptionsMetaBox', 'path' => OPANDA_BIZPANDA_DIR . '/includes/metaboxes/basic-options.php' ); $data[] = array( 'class' => 'OPanda_PreviewMetaBox', 'path' => OPANDA_BIZPANDA_DIR . '/includes/metaboxes/preview.php' ); $data[] = array( 'class' => 'OPanda_ManualLockingMetaBox', 'path' => OPANDA_BIZPANDA_DIR . '/includes/metaboxes/manual-locking.php' ); $data[] = array( 'class' => 'OPanda_BulkLockingMetaBox', 'path' => OPANDA_BIZPANDA_DIR . '/includes/metaboxes/bulk-locking.php' ); $data[] = array( 'class' => 'OPanda_TermsOptionsMetaBox', 'path' => OPANDA_BIZPANDA_DIR . '/includes/metaboxes/terms-privacy.php' ); } $data = apply_filters( "opanda_item_type_metaboxes", $data, $typeName ); $data = apply_filters( "opanda_{$typeName}_type_metaboxes", $data ); foreach( $data as $metabox ) { require_once $metabox['path']; FactoryMetaboxes321::registerFor( new $metabox['class']( $bizpanda ), OPANDA_POST_TYPE, $bizpanda); } } add_action( 'init', 'opanda_add_meta_boxes' );