plugin_url = plugins_url() . '/assets-manager'; } /** * Runs essential pieces of plugin to run within WordPress */ public function init() { $this->hooks(); } /** * Registers WordPress actions */ private function hooks() { add_action( 'add_meta_boxes', array( $this, 'assets_manager_register_meta_box' ) ); add_action( 'admin_enqueue_scripts', array( $this, 'load_admin_scripts' ) ); } /** * Add meta boxes to asset type post edit page */ public function assets_manager_register_meta_box() { # meta box on plupload page add_meta_box( 'upload_assets', __( 'Upload Assets', 'upload_assets_textdomain' ), array( $this, 'assets_manager_upload_meta_box' ), 'asset', 'normal' ); add_meta_box( 'attached_assets', __( 'Attached Assets', 'attached_assets_textdomain' ), array( $this, 'assets_manager_attached_meta_box' ), 'asset', 'normal' ); } /** * Upload box */ public function assets_manager_upload_meta_box() { ?> get_asset_attachments_ordered( $post->ID ); ?>
$post_id, 'post_type' => 'attachment', 'order' => 'ASC', 'orderby' => 'meta_value_num', 'meta_key' => 'order', 'posts_per_page' => - 1 ) ); return $attachments; } /** * Extracts time unit value from set value * * @param $asset * * @return mixed */ public function get_expires_val( $expires ) { $expires_val = current( explode( ' ', $expires ) ); return $expires_val; } /** * Builds option for select with time unit * * @param $expires * * @return string */ private function build_timeTerm_options( $expires ) { $selected_unit = $this->get_expires_unit( $expires ); $units = array( 'day' => 'Day(s)', 'week' => 'Week(s)', 'month' => 'Month(s)', 'year' => 'Year(s)', 'never' => 'Never' ); $options = ''; foreach ( $units as $unit => $label ) { $options .= ''; } return $options; } /** * Extracts time unit from set value * * @param $expires * * @return mixed */ private function get_expires_unit( $expires ) { $selected_unit = rtrim( end( explode( ' ', $expires ) ), 's' ); return $selected_unit; } /** * Enqueues scripts for page */ public function load_admin_scripts() { global $post; if ( is_admin() && is_object( $post ) && 'asset' === $post->post_type ) { wp_enqueue_script( 'wp_assets', $this->plugin_url . '/js/assets-manager.js', array( 'jquery', 'jquery-ui-sortable', 'plupload-all' ), 201510 ); wp_enqueue_style( 'wp_assets_admin', $this->plugin_url . '/css/assets-manager.css' ); wp_localize_script( 'wp_assets', 'AM_Ajax', array( 'ajaxurl' => admin_url( 'admin-ajax.php' ), 'amNonce' => wp_create_nonce( 'update-amNonce' ) ) ); } } }