| 1 |
<?php |
| 2 |
/** |
| 3 |
* MainWP Bulk Add Handler |
| 4 |
* |
| 5 |
* Handles Bulk addition of Pages, Posts, User Import, User Addition & Admin Users Password. |
| 6 |
* |
| 7 |
* @package MainWP/Dashboard |
| 8 |
*/ |
| 9 |
|
| 10 |
namespace MainWP\Dashboard; |
| 11 |
|
| 12 |
// Exit if accessed directly. |
| 13 |
if ( ! defined( 'ABSPATH' ) ) { |
| 14 |
exit; |
| 15 |
} |
| 16 |
|
| 17 |
/** |
| 18 |
* Class MainWP_Bulk_Add |
| 19 |
* |
| 20 |
* @used-by MainWP_Page::BulkAddPage |
| 21 |
* @used-by MainWP_Post::BulkAddPost |
| 22 |
* @used-by MainWP_User::do_bulk_add |
| 23 |
* @used-by MainWP_User::do_import |
| 24 |
* @used-by MainWP_Bulk_Update_Admin_Passwords::BulkAddUser |
| 25 |
*/ |
| 26 |
class MainWP_Bulk_Add { // phpcs:ignore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR.nore Generic.Classes.OpeningBraceSameLine.ContentAfterBrace -- NOSONAR. |
| 27 |
|
| 28 |
/** |
| 29 |
* Method get_class_name() |
| 30 |
* |
| 31 |
* Get Class Name. |
| 32 |
* |
| 33 |
* @return object __CLASS__ |
| 34 |
*/ |
| 35 |
public static function get_class_name() { |
| 36 |
return __CLASS__; |
| 37 |
} |
| 38 |
|
| 39 |
/** |
| 40 |
* Method posting_bulk_handler() |
| 41 |
* |
| 42 |
* @param mixed $data Data to process. |
| 43 |
* @param object $website The website object. |
| 44 |
* @param object $output Function output object. |
| 45 |
* |
| 46 |
* @return mixed $output |
| 47 |
* |
| 48 |
* @uses \MainWP\Dashboard\MainWP_Error_Helper::get_error_message() |
| 49 |
* @uses \MainWP\Dashboard\MainWP_Exception |
| 50 |
* @uses \MainWP\Dashboard\MainWP_Logger::warning_for_website() |
| 51 |
* @uses \MainWP\Dashboard\MainWP_System_Utility::get_child_response() |
| 52 |
*/ |
| 53 |
public static function posting_bulk_handler( $data, $website, &$output ) { //phpcs:ignore -- NOSONAR - complex. |
| 54 |
if ( MainWP_Demo_Handle::get_instance()->is_demo_website( $website ) ) { |
| 55 |
return; |
| 56 |
} |
| 57 |
if ( preg_match( '/<mainwp>(.*)<\/mainwp>/', $data, $results ) > 0 ) { |
| 58 |
$result = $results[1]; |
| 59 |
$information = MainWP_System_Utility::get_child_response( base64_decode( $result ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode used for http encoding compatible. |
| 60 |
|
| 61 |
if ( is_array( $information ) && isset( $information['other_data']['new_post_data'] ) ) { // created/updated post/page. |
| 62 |
do_action( 'mainwp_post_created', $website, 'newpost', $information['other_data']['new_post_data'] ); |
| 63 |
} |
| 64 |
|
| 65 |
if ( is_array( $information ) && isset( $information['other_data']['new_user_data'] ) ) { // created user. |
| 66 |
$data = $information['other_data']['new_user_data']; |
| 67 |
/** |
| 68 |
* Fires immediately after new user action. |
| 69 |
* |
| 70 |
* @since 4.5.1.1 |
| 71 |
*/ |
| 72 |
do_action( 'mainwp_user_action', $website, 'created', $data ); |
| 73 |
} |
| 74 |
|
| 75 |
if ( is_array( $information ) && isset( $information['other_data']['update_admin_password'] ) ) { // created user. |
| 76 |
$data = $information['other_data']['update_admin_password']; |
| 77 |
/** |
| 78 |
* Fires immediately after update admin password action. |
| 79 |
* |
| 80 |
* @since 4.5.1.1 |
| 81 |
*/ |
| 82 |
do_action( 'mainwp_user_action', $website, 'newadminpassword', $data ); |
| 83 |
} |
| 84 |
|
| 85 |
if ( isset( $information['added'] ) ) { |
| 86 |
$output->ok[ $website->id ] = '1'; |
| 87 |
if ( isset( $information['link'] ) ) { |
| 88 |
$output->link[ $website->id ] = esc_html( $information['link'] ); |
| 89 |
} |
| 90 |
if ( isset( $information['added_id'] ) ) { |
| 91 |
$output->added_id[ $website->id ] = esc_html( $information['added_id'] ); |
| 92 |
} |
| 93 |
} elseif ( isset( $information['error'] ) ) { |
| 94 |
$output->errors[ $website->id ] = esc_html__( 'ERROR: ', 'mainwp' ) . esc_html( $information['error'] ); |
| 95 |
} else { |
| 96 |
$output->errors[ $website->id ] = esc_html__( 'Undefined error! Please reinstall the MainWP Child plugin on the child site', 'mainwp' ); |
| 97 |
} |
| 98 |
} else { |
| 99 |
MainWP_Logger::instance()->debug_for_website( $website, 'posting_bulk_handler', '[' . $website->url . '] Result was: [data-start]' . $data . '[data-end]' ); |
| 100 |
$output->errors[ $website->id ] = MainWP_Error_Helper::get_error_message( new MainWP_Exception( 'NOMAINWP', $website->url ) ); //phpcs:ignore WordPress.Security.EscapeOutput.ExceptionNotEscaped |
| 101 |
} |
| 102 |
} |
| 103 |
} |
| 104 |
|