Skip to content

Commit

Permalink
Added filter postqueue_add_position #32
Browse files Browse the repository at this point in the history
  • Loading branch information
Maximilian Strehse committed Jul 11, 2019
1 parent 02e6b32 commit c49c721
Show file tree
Hide file tree
Showing 3 changed files with 279 additions and 256 deletions.
112 changes: 60 additions & 52 deletions classes/metabox.php
@@ -1,49 +1,49 @@
<?php
/**
* Generated by the WordPress Meta Box Generator at http://goo.gl/8nwllb
* User: jana
* Date: 12.12.17
* Time: 18:00
*/
* Generated by the WordPress Meta Box Generator at http://goo.gl/8nwllb
* User: jana
* Date: 12.12.17
* Time: 18:00
*/

namespace Postqueue;

class MetaBox {

/**
* @var Store
*/
* @var Store
*/
public $store;

private $screens;

/**
* Post constructor.
*
* @param Plugin $plugin
*/
* Post constructor.
*
* @param Plugin $plugin
*/
function __construct(Plugin $plugin) {
$this->plugin = $plugin;
$this->store = $plugin->store;
$this->screens = get_post_types( array('public' => true) ); //@todo could get a setting page where to choose for which post_types postqueues should be available
/**
* registers add_meta_boxes action that adds metaboxes to post edit
*/
* registers add_meta_boxes action that adds metaboxes to post edit
*/
add_action( 'add_meta_boxes', array( $this, 'add_meta_boxes' ) );

/**
* register ajax callbacks for this metabox
*/
add_action( 'wp_ajax_postqueue_add_post', array( $this, 'ajax_callback_add_post' ) );
add_action( 'wp_ajax_postqueue_remove_post', array( $this, 'ajax_callback_remove_post' ) );
* register ajax callbacks for this metabox
*/
add_action( 'wp_ajax_postqueue_add_post', array( $this, 'ajax_callback_add_post' ) );
add_action( 'wp_ajax_postqueue_remove_post', array( $this, 'ajax_callback_remove_post' ) );
}

/**
* Hooks into WordPress' add_meta_boxes function.
* Goes through screens (post types) and adds the meta box.
*/
* Hooks into WordPress' add_meta_boxes function.
* Goes through screens (post types) and adds the meta box.
*/
public function add_meta_boxes() {
foreach ( $this->screens as $screen ) {
add_meta_box(
'postqueue',
Expand All @@ -55,16 +55,16 @@ public function add_meta_boxes() {
);
}
}

/**
* Generates the HTML for the meta box
*
* @param object $post WordPress post object
*/
* Generates the HTML for the meta box
*
* @param object $post WordPress post object
*/
public function render( $post ) {
/**
* Add css and javascript
*/
/**
* Add css and javascript
*/
wp_enqueue_style(
'postqueue-metabox-css',
$this->plugin->url . 'css/postqueue-metabox.css',
Expand All @@ -80,36 +80,44 @@ public function render( $post ) {
false
);
wp_localize_script( 'postqueue-metabox', 'PostqueueMetaBoxL10n', array(
'postremoved' => esc_html__( 'Post successfully removed from postqueue.', Plugin::DOMAIN ),
'postadded' => esc_html__( 'Post successfully added to postqueue.', Plugin::DOMAIN ),
'pleasechoose' => esc_html__( 'Please choose a postqueue!', Plugin::DOMAIN ),
'erroroccured' => esc_html__( 'An error occured while sending the request. Please try again later.', Plugin::DOMAIN ),
'removepostfromthispostqueue' => esc_html__( 'Remove post from this postqueue.', Plugin::DOMAIN ),
'notstoredyet' => esc_html__( 'This post is not saved in any postqueue yet. You can add it to one below.', Plugin::DOMAIN )
));
'postremoved' => esc_html__( 'Post successfully removed from postqueue.', Plugin::DOMAIN ),
'postadded' => esc_html__( 'Post successfully added to postqueue.', Plugin::DOMAIN ),
'pleasechoose' => esc_html__( 'Please choose a postqueue!', Plugin::DOMAIN ),
'erroroccured' => esc_html__( 'An error occured while sending the request. Please try again later.', Plugin::DOMAIN ),
'removepostfromthispostqueue' => esc_html__( 'Remove post from this postqueue.', Plugin::DOMAIN ),
'notstoredyet' => esc_html__( 'This post is not saved in any postqueue yet. You can add it to one below.', Plugin::DOMAIN )
));
$store = $this->store;
require $this->plugin->dir .'partials/postqueue-metabox.tpl.php';
}

/**
* Callback function for the add post action
*/
* Callback function for the add post action
*/
function ajax_callback_add_post() {
$post_id = intval( $_POST['postid'] );
$queue_id = intval( $_POST['queueid'] );
$this->store->add_post_to_queue( $post_id, $queue_id );
echo "Postqueue ID: " . $queue_id;
wp_die(); // this is required to terminate immediately and return a proper response
$post_id = intval( $_POST['postid'] );
$queue_id = intval( $_POST['queueid'] );

$position = \apply_filters(Plugin::FILTER_ADD_POSITION, null);

if(in_array($position, ['first', 'last'])){
$this->store->queue_add( $queue_id, $post_id, $position );
}else{
$this->store->add_post_to_queue( $post_id, $queue_id );
}

echo "Postqueue ID: " . $queue_id;
wp_die(); // this is required to terminate immediately and return a proper response
}

/**
* Callback function for the remove post action
*/
* Callback function for the remove post action
*/
function ajax_callback_remove_post() {
$post_id = intval( $_POST['postid'] );
$queue_id = intval( $_POST['queueid'] );
$this->store->remove_post_from_queue( $post_id, $queue_id );
echo "Postqueue ID: " . $queue_id;
wp_die(); // this is required to terminate immediately and return a proper response
$post_id = intval( $_POST['postid'] );
$queue_id = intval( $_POST['queueid'] );
$this->store->remove_post_from_queue( $post_id, $queue_id );
echo "Postqueue ID: " . $queue_id;
wp_die(); // this is required to terminate immediately and return a proper response
}
}

0 comments on commit c49c721

Please sign in to comment.