get_websites_by_client_ids( $client_id, array( 'select_data' => $data_fields ) );
if ( $websites ) {
foreach ( $websites as $website ) {
if ( empty( $website->recent_posts ) ) {
continue;
}
$posts = json_decode( $website->recent_posts, 1 );
if ( empty( $posts ) ) {
continue;
}
foreach ( $posts as $post ) {
$post['website'] = (object) array(
'id' => $website->id,
'url' => $website->url,
'name' => $website->name,
);
$allPosts[] = $post;
}
}
}
} else {
if ( $current_wpid ) {
$sql = MainWP_DB::instance()->get_sql_website_by_id( $current_wpid );
$individual = true;
} else {
$sql = MainWP_DB::instance()->get_sql_websites_for_current_user();
$individual = false;
}
$websites = MainWP_DB::instance()->query( $sql );
if ( $websites ) {
while ( $websites && ( $website = MainWP_DB::fetch_object( $websites ) ) ) {
if ( empty( $website->recent_posts ) ) {
continue;
}
$posts = json_decode( $website->recent_posts, 1 );
if ( empty( $posts ) ) {
continue;
}
foreach ( $posts as $post ) {
$post['website'] = (object) array(
'id' => $website->id,
'url' => $website->url,
'name' => $website->name,
);
$allPosts[] = $post;
}
}
MainWP_DB::free_result( $websites );
}
}
static::render_top_grid();
/**
* Action: mainwp_recent_posts_widget_top
*
* Fires at the top of the Recent Posts widget.
*
* @since 4.1
*/
do_action( 'mainwp_recent_posts_widget_top' );
?>
esc_html__( 'The post has been published.', 'mainwp' ) ) ) );
}
/**
* Method approve()
*
* Approve Post.
*/
public static function approve() {
static::action( 'publish' );
die( wp_json_encode( array( 'result' => esc_html__( 'The post has been approved.', 'mainwp' ) ) ) );
}
/**
* Method unpublish()
*
* Unpublish Post.
*/
public static function unpublish() {
static::action( 'unpublish' );
die( wp_json_encode( array( 'result' => esc_html__( 'The post has been unpublished.', 'mainwp' ) ) ) );
}
/**
* Method trash()
*
* Trash Post.
*/
public static function trash() {
static::action( 'trash' );
die( wp_json_encode( array( 'result' => esc_html__( 'The post has been moved to the trash.', 'mainwp' ) ) ) );
}
/**
* Method delete()
*
* Delete Post.
*/
public static function delete() {
static::action( 'delete' );
die( wp_json_encode( array( 'result' => esc_html__( 'The post has been permanently deleted.', 'mainwp' ) ) ) );
}
/**
* Method restore()
*
* Restore Post.
*/
public static function restore() {
static::action( 'restore' );
die( wp_json_encode( array( 'result' => esc_html__( 'The post has been restored.', 'mainwp' ) ) ) );
}
/**
* Method action()
*
* Initiate try catch for chosen Action
*
* @param string $pAction Post Action.
* @param string $type Post type.
*
* @throws \MainWP_Exception Error message.
*
* @uses \MainWP\Dashboard\MainWP_DB::get_website_by_id()
* @uses \MainWP\Dashboard\MainWP_Error_Helper::get_error_message()
* @uses \MainWP\Dashboard\MainWP_Exception
* @uses \MainWP\Dashboard\MainWP_Connect::fetch_url_authed()
* @uses \MainWP\Dashboard\MainWP_System_Utility::can_edit_website()
*/
public static function action( $pAction, $type = 'post' ) {
$postId = isset( $_POST['postId'] ) ? intval( $_POST['postId'] ) : false; // phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.NonceVerification.Missing
$websiteId = isset( $_POST['websiteId'] ) ? intval( $_POST['websiteId'] ) : false; // phpcs:ignore WordPress.Security.NonceVerification.Recommended,WordPress.Security.NonceVerification.Missing
if ( empty( $postId ) || empty( $websiteId ) ) {
die( wp_json_encode( array( 'error' => 'Post ID or site ID not found. Please, reload the page and try again.' ) ) );
}
$website = MainWP_DB::instance()->get_website_by_id( $websiteId );
if ( ! MainWP_System_Utility::can_edit_website( $website ) ) {
die( wp_json_encode( array( 'error' => 'You can not edit this website!' ) ) );
}
if ( MainWP_System_Utility::is_suspended_site( $website ) ) {
die(
wp_json_encode(
array(
'error' => esc_html__( 'Suspended site.', 'mainwp' ),
'errorCode' => 'SUSPENDED_SITE',
)
)
);
}
/**
* Action: mainwp_before_post_action
*
* Fires before post/page publish/unpublish/trash/delete/restore actions.
*
* @since 4.1
*/
do_action( 'mainwp_before_post_action', $type, $pAction, $postId, $website );
try {
$information = MainWP_Connect::fetch_url_authed(
$website,
'post_action',
array(
'action' => $pAction,
'id' => $postId,
)
);
} catch ( MainWP_Exception $e ) {
$information = array( 'error' => MainWP_Error_Helper::get_error_message( $e ) );
}
/**
* Action: mainwp_after_post_action
* Fires after post/page publish/unpublish/trash/delete/restore actions.
*
* @since 4.1
*/
do_action( 'mainwp_after_post_action', $information, $type, $pAction, $postId, $website );
mainwp_get_actions_handler_instance()->do_action_mainwp_post_action( $website, $pAction, $information, $postId, $type );
if ( is_array( $information ) && isset( $information['error'] ) ) {
die( wp_json_encode( $information ) );
} elseif ( ! isset( $information['status'] ) || ( 'SUCCESS' !== $information['status'] ) ) {
die( wp_json_encode( array( 'error' => 'Unexpected error!' ) ) );
}
}
}