Merge pull request #172 from kwcjr/Documentation

Documentation
This commit is contained in:
Thang Hoang Van 2020-05-29 17:42:35 +07:00 committed by GitHub
commit d76f9a4186
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
7 changed files with 254 additions and 20 deletions

View file

@ -9,6 +9,8 @@ namespace MainWP\Child;
/**
* Class MainWP_Child_Install
*
* @package MainWP\Child
*/
class MainWP_Child_Install {

View file

@ -1,27 +1,46 @@
<?php
/**
* MainWP Child Misc functions
*
* This file is for misc functions that don't really belong anywhere else.
*/
namespace MainWP\Child;
// phpcs:disable WordPress.WP.AlternativeFunctions -- to use external code, third party credit.
/**
* Class MainWP_Child_Misc
*
* @package MainWP\Child
*/
class MainWP_Child_Misc {
/**
* @static
* @var null Holds the Public static instance of MainWP_Child_Misc.
*/
protected static $instance = null;
/**
* Method get_class_name()
*
* Get Class Name.
*
* @return object
* @return string
*/
public static function get_class_name() {
return __CLASS__;
}
/**
* MainWP_Child_Misc constructor.
*/
public function __construct() {
}
/**
* Create a public static instance of MainWP_Child_Misc.
*
* @return MainWP_Child_Misc|null
*/
public static function get_instance() {
if ( null === self::$instance ) {
self::$instance = new self();
@ -29,6 +48,9 @@ class MainWP_Child_Misc {
return self::$instance;
}
/**
* Prepare Child Site favicon.
*/
public function get_site_icon() {
$information = array();
$url = $this->get_favicon( true );
@ -38,6 +60,12 @@ class MainWP_Child_Misc {
MainWP_Helper::write( $information );
}
/**
* Get Child Site favicon.
*
* @param bool $parse_page Whether or not to parse the page. Default: false.
* @return string|bool Return $favi_url on success, FALSE on failure.
*/
public function get_favicon( $parse_page = false ) {
$favi_url = '';
@ -80,6 +108,12 @@ class MainWP_Child_Misc {
}
}
/**
* Try to parse Child Site url for favicon.
*
* @param $site_url Child Site URL.
* @return mixed|string $favi_url parsed favicon.
*/
private function try_to_parse_favicon( $site_url ) {
$request = wp_remote_get( $site_url, array( 'timeout' => 50 ) );
$favi = '';
@ -112,6 +146,9 @@ class MainWP_Child_Misc {
return $favi_url;
}
/**
* Get security stats.
*/
public function get_security_stats() {
$information = array();
@ -130,6 +167,9 @@ class MainWP_Child_Misc {
}
/**
* Perform Child Site security fixes.
*/
public function do_security_fix() {
$sync = false;
if ( 'all' === $_POST['feature'] ) {
@ -207,6 +247,9 @@ class MainWP_Child_Misc {
MainWP_Helper::write( $information );
}
/**
* Perform Child Site security unfixes.
*/
public function do_security_un_fix() {
$information = array();
@ -262,6 +305,11 @@ class MainWP_Child_Misc {
MainWP_Helper::write( $information );
}
/**
* Method settings_tools()
*
* @deprecated Unused Element
*/
public function settings_tools() {
if ( isset( $_POST['action'] ) ) {
switch ( $_POST['action'] ) {
@ -289,6 +337,9 @@ class MainWP_Child_Misc {
}
}
/**
* Try to upload file to Child Site.
*/
public function uploader_action() {
$file_url = base64_decode( $_POST['url'] ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
$path = $_POST['path'];
@ -336,8 +387,18 @@ class MainWP_Child_Misc {
}
/**
* Child Site file uploader.
*
* @param string $file_url URL of file to be uploaded.
* @param string $path Path to upload to.
* @param string $file_name Name of file to upload.
*
* @return string[] Full path and file name of uploaded file.
* @throws \Exception Error: Copy file.
*/
public function uploader_upload_file( $file_url, $path, $file_name ) {
// to fix uploader extension rename htaccess file issue.
// Fixes: Uploader Extension rename htaccess file issue.
if ( '.htaccess' != $file_name && '.htpasswd' != $file_name ) {
$file_name = sanitize_file_name( $file_name );
}
@ -377,6 +438,9 @@ class MainWP_Child_Misc {
return array( 'path' => $full_file_name );
}
/**
* Initiate Code Snippet action: run_snippet, save_snippet, delete_snippet.
*/
public function code_snippet() {
$action = $_POST['action'];
@ -413,6 +477,16 @@ class MainWP_Child_Misc {
MainWP_Helper::write( $information );
}
/**
* Save code snippet.
*
* @param string $slug Snippet slug.
* @param string $type Type of snippet.
* @param string $code Snippet code.
* @param array $snippets Snippets array.
*
* @return array $return Status response.
*/
private function snippet_save_snippet( $slug, $type, $code, $snippets ) {
$return = array();
if ( 'C' === $type ) { // save into wp-config file.
@ -429,6 +503,15 @@ class MainWP_Child_Misc {
return $return;
}
/**
* Delete code snippets.
*
* @param string $slug Snippet slug.
* @param string $type Type of snippet.
* @param array $snippets Snippets array.
*
* @return array $return Status response.
*/
private function snippet_delete_snippet( $slug, $type, $snippets ) {
$return = array();
if ( 'C' === $type ) { // delete in wp-config file.
@ -448,6 +531,14 @@ class MainWP_Child_Misc {
return $return;
}
/**
* Update Child Site wp-config.php file.
*
* @param $action Action to perform: Delete, Save.
* @param $slug Snippet slug.
* @param string $code Code snippet.
* @return bool true|false.
*/
public function snippet_update_wp_config( $action, $slug, $code = '' ) {
$config_file = '';

View file

@ -309,7 +309,8 @@ class MainWP_Child {
*
* Initiate the chech login process.
*
* @uses MainWP_Connect::instance()->check_login() Auto-login user to the child site when the Open WP Admin feature from the MainWP Dashboard is used.
* @uses MainWP_Connect::instance()->check_login() Auto-login user to the child site when
* the Open WP Admin feature from the MainWP Dashboard is used.
*/
public function init_check_login() {
MainWP_Connect::instance()->check_login();
@ -351,7 +352,7 @@ class MainWP_Child {
/**
* Method deactivation()
*
* Deactivate the MainWP Child plugin and delted unwanted data.
* Deactivate the MainWP Child plugin and delete unwanted data.
*
* @param bool $deact Whether or not to deactivate pugin. Default: true.
*/
@ -388,7 +389,7 @@ class MainWP_Child {
/**
* Method activation()
*
* Activate the MainWP Child plugin and delted unwanted data.
* Activate the MainWP Child plugin and delete unwanted data.
*/
public function activation() {
$mu_plugin_enabled = apply_filters( 'mainwp_child_mu_plugin_enabled', false );

View file

@ -1,21 +1,37 @@
<?php
/**
* MainWP Clone Page.
*/
namespace MainWP\Child;
/**
* Class MainWP_Clone_Page
*
* @package MainWP\Child
*/
class MainWP_Clone_Page {
/**
* @static
* @var null Holds the Public static instance of MainWP_Clone_Page.
*/
protected static $instance = null;
/**
* Method get_class_name()
*
* Get Class Name.
*
* @return object
* @return string
*/
public static function get_class_name() {
return __CLASS__;
}
/**
* Create a public static instance of MainWP_Clone_Page.
*
* @return MainWP_Clone_Page|null
*/
public static function get() {
if ( null === self::$instance ) {
self::$instance = new self();
@ -23,6 +39,11 @@ class MainWP_Clone_Page {
return self::$instance;
}
/**
* Method print_scripts()
*
* @deprecated Unused Element
*/
public static function print_scripts() {
wp_enqueue_script( 'jquery-ui-tooltip' );
wp_enqueue_script( 'jquery-ui-autocomplete' );
@ -48,6 +69,9 @@ class MainWP_Clone_Page {
}
/**
* Render Clone page.
*/
public static function render() {
$uploadError = false;
$uploadFile = false;
@ -100,6 +124,15 @@ class MainWP_Clone_Page {
self::render_java_script();
}
/**
* Render clone form.
*
* @param array $sitesToClone Sites that may be cloned.
* @param mixed $uploadFile Path to File.
* @param string $uploadSize Size of upload.
* @param bool $error true|false.
* @param string $uploadError Upload error message.
*/
private static function render_form( $sitesToClone, $uploadFile, $uploadSize, $error, $uploadError ) {
if ( ! empty( $uploadFile ) ) {
@ -173,6 +206,9 @@ class MainWP_Clone_Page {
<?php
}
/**
* Render normal restore page.
*/
public static function render_normal_restore() {
$uploadError = false;
$uploadFile = false;
@ -264,6 +300,10 @@ class MainWP_Clone_Page {
* Author: Dion Hulse
* Author URI: http://dd32.id.au/
*/
/**
* Render Clone from server
* Allows the Media Manager to add files from the webservers filesystem. Note: All files are copied to the uploads directory.
*/
private static function render_clone_from_server() {
$page = $_REQUEST['page'];
$sitesToClone = get_option( 'mainwp_child_clone_sites' );
@ -343,6 +383,12 @@ class MainWP_Clone_Page {
self::render_clone_from_server_form( $current_dir, $url );
}
/**
* Render clone from server form.
*
* @param string $current_dir Current parent directory
* @param string $url URL of file to upload.
*/
private static function render_clone_from_server_form( $current_dir, $url ) {
$dir_files = scandir( $current_dir );
@ -425,6 +471,9 @@ class MainWP_Clone_Page {
<?php
}
/**
* Render javascript.
*/
public static function render_java_script() {
$uploadSizeInBytes = min( MainWP_Helper::return_bytes( ini_get( 'upload_max_filesize' ) ), MainWP_Helper::return_bytes( ini_get( 'post_max_size' ) ) );
$uploadSize = MainWP_Helper::human_filesize( $uploadSizeInBytes );
@ -800,6 +849,9 @@ class MainWP_Clone_Page {
<?php
}
/**
* Render style.
*/
public static function render_style() {
?>
<style>
@ -1063,6 +1115,11 @@ class MainWP_Clone_Page {
<?php
}
/**
* Method permalink_admin_notice()
*
* @deprecated Unused Element.
*/
public static function permalink_admin_notice() {
if ( isset( $_POST['permalink_structure'] ) || isset( $_POST['category_base'] ) || isset( $_POST['tag_base'] ) ) {
return;
@ -1094,6 +1151,9 @@ class MainWP_Clone_Page {
<?php
}
/**
* Render Restore.
*/
public static function render_restore() {
if ( '' === session_id() ) {
session_start();

View file

@ -1,12 +1,35 @@
<?php
/**
* MainWP Custom Post Type
*
* This file handles all custom post types.
*/
namespace MainWP\Child;
/**
* Class MainWP_Custom_Post_Type
*
* @package MainWP\Child
*/
class MainWP_Custom_Post_Type {
public static $instance = null;
public static $information = array();
public $plugin_translate = 'mainwp-child';
/**
* @static
* @var null Holds the Public static instance of MainWP_Custom_Post_Type.
*/
public static $instance = null;
/** @var array Response array. */
public static $information = array();
/** @var string Plugin slug. */
public $plugin_translate = 'mainwp-child';
/**
* Create a public static instance of MainWP_Custom_Post_Type.
*
* @return MainWP_Custom_Post_Type|null
*/
public static function instance() {
if ( null == self::$instance ) {
self::$instance = new self();
@ -15,7 +38,16 @@ class MainWP_Custom_Post_Type {
return self::$instance;
}
/**
* Custom post type action.
*/
public function action() {
/**
* Method mainwp_custom_post_type_handle_fatal_error()
*
* Custom post type fatal error handler.
*/
function mainwp_custom_post_type_handle_fatal_error() {
$error = error_get_last();
if ( isset( $error['type'] ) && E_ERROR === $error['type'] && isset( $error['message'] ) ) {
@ -29,11 +61,12 @@ class MainWP_Custom_Post_Type {
} else {
$data = serialize( $data ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions
}
die( '<mainwp>' . base64_encode( $data ) . '</mainwp>' ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatible..
die( '<mainwp>' . base64_encode( $data ) . '</mainwp>' ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for http encode compatibility.
}
register_shutdown_function( 'MainWP\Child\MainWP_Custom_Post_Type\mainwp_custom_post_type_handle_fatal_error' );
/** @var $information @deprecated Unused local variable 'information'. The value of the variable is overwritten immediately. */
$information = array();
switch ( $_POST['action'] ) {
case 'custom_post_type_import':
@ -50,7 +83,13 @@ class MainWP_Custom_Post_Type {
exit();
}
/**
* Import custom post type.
*
* @return array|string[] $return Response array, or error message on failure.
*/
private function import_custom_post() {
add_filter( 'http_request_host_is_external', '__return_true' );
if ( ! isset( $_POST['data'] ) || strlen( $_POST['data'] ) < 2 ) {
@ -76,10 +115,13 @@ class MainWP_Custom_Post_Type {
return $return;
}
/**
* Search image inside post content and upload it to child
* Search for images inside post content and upload it to Child Site.
*
* @param string $post_content Post content to search.
* @param string $upload_dir Upload directory.
* @param bool $check_image Check if file exists. Default: false.
* @return string|string[] Error message or post content string.
*/
private function search_images( $post_content, $upload_dir, $check_image = false ) {
$foundMatches = preg_match_all( '/(<a[^>]+href=\"(.*?)\"[^>]*>)?(<img[^>\/]*src=\"((.*?)(png|gif|jpg|jpeg))\")/ix', $post_content, $matches, PREG_SET_ORDER );
@ -132,6 +174,15 @@ class MainWP_Custom_Post_Type {
return $post_content;
}
/**
* Insert data into published post.
*
* @param string $data Data to insert.
* @param int $edit_id Post ID to edit.
* @param int $parent_id Post parent ID.
*
* @return array|bool|string[] Response array, true|false, Error message.
*/
private function insert_post( $data, $edit_id, $parent_id = 0 ) {
$data_insert = array();
$data_post = $data['post'];
@ -234,6 +285,13 @@ class MainWP_Custom_Post_Type {
);
}
/**
* Insert custom post data.
*
* @param int $post_id Post ID to update.
* @param string $data Custom data to add.
* @return array|bool|string[] Response array, true|false, Error message.
*/
private function insert_custom_data( $post_id, $data ) {
// MainWP Categories.
@ -296,6 +354,16 @@ class MainWP_Custom_Post_Type {
return true;
}
/**
* Insert post meta.
*
* @param int $post_id Post ID to update.
* @param string $data Meta datat add.
* @param bool $check_image_existed Whether or not to check if image exists. true|false.
* @param bool $is_woocomerce Whether or not the post is a woocommerce product. true|false.
*
* @return array|bool|string[] Response array, true|false, Error message.
*/
private function insert_postmeta( $post_id, $data, $check_image_existed, $is_woocomerce ) {
foreach ( $data['postmeta'] as $key ) {
if ( isset( $key['meta_key'] ) && isset( $key['meta_value'] ) ) {
@ -345,6 +413,14 @@ class MainWP_Custom_Post_Type {
return true;
}
/**
* Upload post meta image.
*
* @param array $product_images Woocomerce product images.
* @param $meta_value
* @param $check_image_existed
* @return array|bool Error message array or TRUE on success.
*/
private function upload_postmeta_image( $product_images, &$meta_value, $check_image_existed ) {
$product_image_gallery = array();
foreach ( $product_images as $product_image ) {

View file

@ -259,6 +259,8 @@ class MainWP_Helper {
* @param string $url URL to check.
*
* @return array $r Updated array containing the request data.
*
* @deprecated Unused Element
*/
public static function reject_unsafe_urls( $r, $url ) {
$r['reject_unsafe_urls'] = false;

View file

@ -226,7 +226,7 @@ class MainWP_Utility {
* @param string $to_email Contains the send to email address.
* @param string $body Contains the email content.
*
* @return srting Return formated email.
* @return string Return formatted email.
*/
public static function format_email( $to_email, $body ) {
return '<br>
@ -317,6 +317,8 @@ class MainWP_Utility {
* Start job if in cron and run query args are set.
*
* @return void
*
* @deprecated Unused Element
*/
public static function cron_active() {
if ( ! defined( 'DOING_CRON' ) || ! DOING_CRON ) {