mirror of
https://github.com/mainwp/mainwp-child.git
synced 2025-09-01 03:58:07 +08:00
Merge branch 'bogdan01' of https://github.com/mainwp/mainwp-child into thang
This commit is contained in:
commit
a4b49cdc81
10 changed files with 431 additions and 21 deletions
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
|
@ -0,0 +1 @@
|
|||
.idea/workspace.xml
|
9
.idea/workspace.xml
generated
9
.idea/workspace.xml
generated
|
@ -75,11 +75,16 @@
|
|||
</entry>
|
||||
</map>
|
||||
</option>
|
||||
<option name="oldMeFiltersMigrated" value="true" />
|
||||
</component>
|
||||
<component name="WindowStateProjectService">
|
||||
<state x="574" y="128" key="#com.intellij.ide.util.MemberChooser" timestamp="1589946624967">
|
||||
<state x="574" y="128" key="#com.intellij.ide.util.MemberChooser" timestamp="1590028259611">
|
||||
<screen x="0" y="0" width="1536" height="824" />
|
||||
</state>
|
||||
<state x="574" y="128" key="#com.intellij.ide.util.MemberChooser/0.0.1536.824@0.0.1536.824" timestamp="1589946624967" />
|
||||
<state x="574" y="128" key="#com.intellij.ide.util.MemberChooser/0.0.1536.824@0.0.1536.824" timestamp="1590028259611" />
|
||||
<state x="501" y="135" key="NewPhpClassDialog" timestamp="1590028599218">
|
||||
<screen x="0" y="0" width="1536" height="824" />
|
||||
</state>
|
||||
<state x="501" y="135" key="NewPhpClassDialog/0.0.1536.824@0.0.1536.824" timestamp="1590028599218" />
|
||||
</component>
|
||||
</project>
|
|
@ -18,7 +18,6 @@ class MainWP_Child_Install {
|
|||
*/
|
||||
protected static $instance = null;
|
||||
|
||||
|
||||
/**
|
||||
* Get Class Name.
|
||||
*
|
||||
|
@ -98,6 +97,11 @@ class MainWP_Child_Install {
|
|||
MainWP_Helper::write( $information );
|
||||
}
|
||||
|
||||
/**
|
||||
* Delete a plugin from the Child Site.
|
||||
*
|
||||
* @param array $plugins An array of plugins to delete.
|
||||
*/
|
||||
private function delete_plugins( $plugins ) {
|
||||
global $mainWPChild;
|
||||
include_once ABSPATH . '/wp-admin/includes/plugin.php';
|
||||
|
@ -209,7 +213,6 @@ class MainWP_Child_Install {
|
|||
MainWP_Helper::write( $information );
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Plugin & Theme Installation functions.
|
||||
*
|
||||
|
@ -274,11 +277,17 @@ class MainWP_Child_Install {
|
|||
MainWP_Helper::write( $information );
|
||||
}
|
||||
|
||||
/**
|
||||
* Hook to set ssl verify.
|
||||
*/
|
||||
public static function no_ssl_filter_function( $r, $url ) {
|
||||
$r['sslverify'] = false;
|
||||
return $r;
|
||||
}
|
||||
|
||||
/**
|
||||
* Include necessary files.
|
||||
*/
|
||||
private function require_files() {
|
||||
if ( file_exists( ABSPATH . '/wp-admin/includes/screen.php' ) ) {
|
||||
include_once ABSPATH . '/wp-admin/includes/screen.php';
|
||||
|
@ -289,6 +298,11 @@ class MainWP_Child_Install {
|
|||
include_once ABSPATH . '/wp-admin/includes/plugin.php';
|
||||
}
|
||||
|
||||
/**
|
||||
* After plugin or theme has been installed.
|
||||
*
|
||||
* @param $result Results array from self::install_plugin_theme
|
||||
*/
|
||||
private function after_installed( $result ) {
|
||||
$args = array(
|
||||
'success' => 1,
|
||||
|
@ -334,6 +348,13 @@ class MainWP_Child_Install {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Alternative installation method.
|
||||
*
|
||||
* @param $url Package URL.
|
||||
* @param $installer Instance of \WP_Upgrader
|
||||
* @return mixed $result Return error messages or TRUE.
|
||||
*/
|
||||
private function try_second_install( $url, $installer ) {
|
||||
$result = $installer->run(
|
||||
array(
|
||||
|
|
|
@ -1,24 +1,42 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* MainWP Child Users.
|
||||
*/
|
||||
namespace MainWP\Child;
|
||||
|
||||
/**
|
||||
* Class MainWP_Child_Users
|
||||
*
|
||||
* @package MainWP\Child
|
||||
*/
|
||||
class MainWP_Child_Users {
|
||||
|
||||
protected static $instance = null;
|
||||
/**
|
||||
* Method get_class_name()
|
||||
*
|
||||
* @static
|
||||
* @var null Holds the Public static instance of MainWP_Child_Users.
|
||||
*/
|
||||
protected static $instance = null;
|
||||
|
||||
/**
|
||||
* Get Class Name.
|
||||
*
|
||||
* @return object
|
||||
* @return string
|
||||
*/
|
||||
public static function get_class_name() {
|
||||
return __CLASS__;
|
||||
}
|
||||
|
||||
/**
|
||||
* MainWP_Child_Users constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a public static instance of MainWP_Child_Users.
|
||||
*
|
||||
* @return MainWP_Child_Users|null
|
||||
*/
|
||||
public static function get_instance() {
|
||||
if ( null === self::$instance ) {
|
||||
self::$instance = new self();
|
||||
|
@ -27,6 +45,11 @@ class MainWP_Child_Users {
|
|||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* MainWP Child User actions: changeRole, update_password, edit, update_user.
|
||||
*
|
||||
* @return array $information[] FAIL|SUCCESS.
|
||||
*/
|
||||
public function user_action() {
|
||||
$action = $_POST['action'];
|
||||
$extra = $_POST['extra'];
|
||||
|
@ -90,6 +113,12 @@ class MainWP_Child_Users {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all users.
|
||||
*
|
||||
* @param bool $number Number parameter.
|
||||
* @return array Return array of $allusers.
|
||||
*/
|
||||
public function get_all_users_int( $number = false ) {
|
||||
$allusers = array();
|
||||
|
||||
|
@ -122,6 +151,12 @@ class MainWP_Child_Users {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Get all Child Site users.
|
||||
*
|
||||
* @param bool $return Whether or not to return. Default: false.
|
||||
* @return array Return array of $allusers.
|
||||
*/
|
||||
public function get_all_users( $return = false ) {
|
||||
$roles = explode( ',', $_POST['role'] );
|
||||
$allusers = array();
|
||||
|
@ -151,6 +186,9 @@ class MainWP_Child_Users {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* Search Child Site users.
|
||||
*/
|
||||
public function search_users() {
|
||||
|
||||
$search_user_role = array();
|
||||
|
@ -214,7 +252,14 @@ class MainWP_Child_Users {
|
|||
}
|
||||
|
||||
|
||||
public function edit_user( $user_id, $data ) { // phpcs:ignore -- ignore complex method notice, see detail at: function edit_user() in the wp/wp-admin/includes/user.php.
|
||||
/**
|
||||
* Edit Child Site user.
|
||||
*
|
||||
* @param $user_id User ID.
|
||||
* @param $data Data to edit.
|
||||
* @return string[]|int Return error string on failure or user ID on success.
|
||||
*/
|
||||
public function edit_user($user_id, $data ) { // phpcs:ignore -- ignore complex method notice, see detail at: function edit_user() in the wp/wp-admin/includes/user.php.
|
||||
$wp_roles = wp_roles();
|
||||
$user = new \stdClass();
|
||||
|
||||
|
@ -354,6 +399,12 @@ class MainWP_Child_Users {
|
|||
return $user_id;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Child Site user to edit.
|
||||
*
|
||||
* @param $user_id User ID.
|
||||
* @return array Return array of $edit_data.
|
||||
*/
|
||||
public function get_user_to_edit( $user_id ) {
|
||||
require_once ABSPATH . 'wp-admin/includes/user.php';
|
||||
$profileuser = get_user_to_edit( $user_id );
|
||||
|
@ -404,6 +455,11 @@ class MainWP_Child_Users {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* New Child Site administrator password.
|
||||
*
|
||||
* @return array $information[] added->true.
|
||||
*/
|
||||
public function new_admin_password() {
|
||||
$new_password = maybe_unserialize( base64_decode( $_POST['new_password'] ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
|
||||
$user = get_user_by( 'login', $_POST['user'] );
|
||||
|
@ -427,6 +483,11 @@ class MainWP_Child_Users {
|
|||
MainWP_Helper::write( $information );
|
||||
}
|
||||
|
||||
/**
|
||||
* Child Site new user.
|
||||
*
|
||||
* @return array $information[] added->true.
|
||||
*/
|
||||
public function new_user() {
|
||||
$new_user = maybe_unserialize( base64_decode( $_POST['new_user'] ) ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
|
||||
$send_password = $_POST['send_password'];
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
<?php
|
||||
/**
|
||||
* MainWP Child Vulnerability Checker
|
||||
*
|
||||
* This file is used for the MainWP Vulnerability Checker Extension.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Credits
|
||||
*
|
||||
|
@ -15,12 +21,34 @@
|
|||
|
||||
namespace MainWP\Child;
|
||||
|
||||
/**
|
||||
* Class MainWP_Child_Vulnerability_Checker
|
||||
*
|
||||
* @package MainWP\Child
|
||||
*/
|
||||
class MainWP_Child_Vulnerability_Checker {
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @var null Holds the Public static instance of MainWP_Child_Vulnerability_Checker.
|
||||
*/
|
||||
public static $instance = null;
|
||||
private $wpvulndb_api = 'https://wpvulndb.com/api/v3/';
|
||||
|
||||
/**
|
||||
* @var string wpvuldb api url.
|
||||
*/
|
||||
private $wpvulndb_api = 'https://wpvulndb.com/api/v3/';
|
||||
|
||||
/**
|
||||
* @var bool Whether or not to use wpvulndb_token. Default: false.
|
||||
*/
|
||||
private $wpvulndb_token = false;
|
||||
|
||||
/**
|
||||
* Create a public static instance of MainWP_Child_Vulnerability_Checker.
|
||||
*
|
||||
* @return MainWP_Child_Vulnerability_Checker|null
|
||||
*/
|
||||
public static function instance() {
|
||||
if ( null === self::$instance ) {
|
||||
self::$instance = new self();
|
||||
|
@ -28,10 +56,16 @@ class MainWP_Child_Vulnerability_Checker {
|
|||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* MainWP_Child_Vulnerability_Checker constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
$this->wpvulndb_token = get_option( 'mainwp_child_wpvulndb_token', '' );
|
||||
}
|
||||
|
||||
/**
|
||||
* MainWP Child Vulnerability Checker actions.
|
||||
*/
|
||||
public function action() {
|
||||
$information = array();
|
||||
if ( ! empty( $this->wpvulndb_token ) ) {
|
||||
|
@ -47,6 +81,11 @@ class MainWP_Child_Vulnerability_Checker {
|
|||
MainWP_Helper::write( $information );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for vulnerabilities.
|
||||
*
|
||||
* @return array Return an array $information[] containing $results[] array.
|
||||
*/
|
||||
public function vulner_recheck() {
|
||||
$result = array();
|
||||
$force = ( isset( $_POST['force'] ) && ! empty( $_POST['force'] ) ) ? true : false;
|
||||
|
@ -60,6 +99,12 @@ class MainWP_Child_Vulnerability_Checker {
|
|||
return $information;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for plugin vulnerabilities.
|
||||
*
|
||||
* @param bool $force Whether or not to force check. Default: false.
|
||||
* @return array Return $result array.
|
||||
*/
|
||||
public function check_plugins( $force = false ) {
|
||||
$result = array();
|
||||
$active_plugins = get_option( 'active_plugins' );
|
||||
|
@ -114,6 +159,12 @@ class MainWP_Child_Vulnerability_Checker {
|
|||
return $result;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check for WP vulnerabilities.
|
||||
*
|
||||
* @param bool $force Whether or not to force check. Default: false.
|
||||
* @return bool|string|null
|
||||
*/
|
||||
public function check_wp( $force = false ) {
|
||||
$wp_vuln = get_transient( 'mainwp_vulnche_trans_wp_json' );
|
||||
$wp_version = str_replace( '.', '', get_bloginfo( 'version' ) );
|
||||
|
@ -124,6 +175,12 @@ class MainWP_Child_Vulnerability_Checker {
|
|||
return $wp_vuln;
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if themes have vunerabilities.
|
||||
*
|
||||
* @param bool $force Whether or not to force check. Default: false.
|
||||
* @return array Return $result array.
|
||||
*/
|
||||
public function check_themes( $force = false ) {
|
||||
|
||||
require_once ABSPATH . 'wp-admin/includes/misc.php';
|
||||
|
@ -186,7 +243,12 @@ class MainWP_Child_Vulnerability_Checker {
|
|||
return $result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Check if content is vulnerable.
|
||||
*
|
||||
* @param $url URL to check.
|
||||
* @return bool|string|null
|
||||
*/
|
||||
public function vulnche_get_content( $url ) {
|
||||
|
||||
// phpcs:disable WordPress.WP.AlternativeFunctions -- to custom.
|
||||
|
@ -209,6 +271,11 @@ class MainWP_Child_Vulnerability_Checker {
|
|||
return $output;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get random useragent.
|
||||
*
|
||||
* @return string User agent string.
|
||||
*/
|
||||
public function get_random_user_agent() {
|
||||
$someUA = array(
|
||||
'Mozilla/5.0 (Windows; U; Windows NT 6.0; fr; rv:1.9.1b1) Gecko/20081007 Firefox/3.1b1',
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
<?php
|
||||
/**
|
||||
* MainWP Child Woocomerce Status
|
||||
*
|
||||
* This file handles syncing woocomerce data with MainWP Dashboard.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Credits
|
||||
*
|
||||
|
@ -13,12 +19,24 @@
|
|||
|
||||
use MainWP\Child\MainWP_Helper;
|
||||
|
||||
|
||||
// phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- to use external code, third party credit.
|
||||
|
||||
/**
|
||||
* Class MainWP_Child_WooCommerce_Status
|
||||
*/
|
||||
class MainWP_Child_WooCommerce_Status {
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @var null Holds the Public static instance of MainWP_Child_WooCommerce_Status.
|
||||
*/
|
||||
public static $instance = null;
|
||||
|
||||
/**
|
||||
* Create a public static instance of MainWP_Child_WooCommerce_Status.
|
||||
*
|
||||
* @return MainWP_Child_WooCommerce_Status|null
|
||||
*/
|
||||
public static function instance() {
|
||||
if ( null === self::$instance ) {
|
||||
self::$instance = new self();
|
||||
|
@ -27,13 +45,22 @@ class MainWP_Child_WooCommerce_Status {
|
|||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* MainWP_Child_WooCommerce_Status constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
add_action( 'mainwp_child_deactivation', array( $this, 'child_deactivation' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* MainWP Child Plugin deactivation hooks.
|
||||
*/
|
||||
public function child_deactivation() {
|
||||
}
|
||||
|
||||
/**
|
||||
* MainWP Child Woocommerce actions: sync_data, report_data, update_wc_db.
|
||||
*/
|
||||
public function action() {
|
||||
$information = array();
|
||||
if ( ! class_exists( 'WooCommerce' ) || ! defined( 'WC_VERSION' ) ) {
|
||||
|
@ -58,10 +85,25 @@ class MainWP_Child_WooCommerce_Status {
|
|||
MainWP_Helper::write( $information );
|
||||
}
|
||||
|
||||
/**
|
||||
* Compare woocommerce versions.
|
||||
*
|
||||
* By default, version_compare returns -1 if the first version is lower than the second,
|
||||
* 0 if they are equal, and 1 if the second is lower.
|
||||
* When using the optional operator argument, the function will return true if the relationship is
|
||||
* the one specified by the operator, false otherwise.
|
||||
*
|
||||
* @return bool|int Comparison response.
|
||||
*/
|
||||
public function is_version_220() {
|
||||
return version_compare( WC()->version, '2.2.0', '>=' );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync Woocommerce data.
|
||||
*
|
||||
* @return array $information Woocommerce data grabed.
|
||||
*/
|
||||
public function sync_data() {
|
||||
global $wpdb;
|
||||
$file = WP_PLUGIN_DIR . '/woocommerce/includes/admin/reports/class-wc-admin-report.php';
|
||||
|
@ -156,6 +198,11 @@ class MainWP_Child_WooCommerce_Status {
|
|||
return $information;
|
||||
}
|
||||
|
||||
/**
|
||||
* Woocommerce report data.
|
||||
*
|
||||
* @return array $information Woocommerce data grabed.
|
||||
*/
|
||||
public function report_data() {
|
||||
global $wpdb;
|
||||
$file = WP_PLUGIN_DIR . '/woocommerce/includes/admin/reports/class-wc-admin-report.php';
|
||||
|
@ -247,8 +294,10 @@ class MainWP_Child_WooCommerce_Status {
|
|||
return $information;
|
||||
}
|
||||
|
||||
/**
|
||||
* sync Woocommerce data for current month.
|
||||
*/
|
||||
public function sync_data_two() {
|
||||
// sync data for current month.
|
||||
$start_date = date( 'Y-m-01 00:00:00', time() ); // phpcs:ignore -- local time.
|
||||
$end_date = date( 'Y-m-d H:i:s', time() ); // phpcs:ignore -- local time.
|
||||
|
||||
|
@ -258,6 +307,9 @@ class MainWP_Child_WooCommerce_Status {
|
|||
return $this->get_woocom_data( $start_date, $end_date );
|
||||
}
|
||||
|
||||
/**
|
||||
* Sync Woocomerce data for specific date range.
|
||||
*/
|
||||
public function report_data_two() {
|
||||
$start_date = $_POST['start_date'];
|
||||
$end_date = $_POST['end_date'];
|
||||
|
@ -265,6 +317,11 @@ class MainWP_Child_WooCommerce_Status {
|
|||
return $this->get_woocom_data( $start_date, $end_date );
|
||||
}
|
||||
|
||||
/**
|
||||
* Check if woocomerce DB needs to be updated.
|
||||
*
|
||||
* @return bool true|false.
|
||||
*/
|
||||
public function check_db_update() {
|
||||
if ( version_compare( get_option( 'woocommerce_db_version' ), WC_VERSION, '<' ) ) {
|
||||
return true;
|
||||
|
@ -272,6 +329,13 @@ class MainWP_Child_WooCommerce_Status {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Get Woocommerce data.
|
||||
*
|
||||
* @param $start_date Start Date.
|
||||
* @param $end_date End Date.
|
||||
* @return array $information Woocommerce data grabed.
|
||||
*/
|
||||
public function get_woocom_data( $start_date, $end_date ) {
|
||||
global $wpdb;
|
||||
$file = WP_PLUGIN_DIR . '/woocommerce/includes/admin/reports/class-wc-admin-report.php';
|
||||
|
@ -357,6 +421,11 @@ class MainWP_Child_WooCommerce_Status {
|
|||
return $information;
|
||||
}
|
||||
|
||||
/**
|
||||
* Update Woocommerce Database.
|
||||
*
|
||||
* @return string[] Success.
|
||||
*/
|
||||
private static function update_wc_db() {
|
||||
include_once WC()->plugin_path() . '/includes/class-wc-background-updater.php';
|
||||
$background_updater = new WC_Background_Updater();
|
||||
|
|
|
@ -1,10 +1,20 @@
|
|||
<?php
|
||||
|
||||
/**
|
||||
* MainWP Child Plugin Debug.
|
||||
*/
|
||||
namespace MainWP\Child;
|
||||
|
||||
/**
|
||||
* Class MainWP_Debug
|
||||
*
|
||||
* @package MainWP\Child
|
||||
*/
|
||||
class MainWP_Debug {
|
||||
|
||||
/**
|
||||
* @param $mainWPChild MainWP_Child
|
||||
* Render MainWP Backup & test debugging output.
|
||||
*
|
||||
* @param $mainWPChild MainWP_Child Instance.
|
||||
*/
|
||||
public static function process( &$mainWPChild ) {
|
||||
if ( ! isset( $_GET['mainwpdebug'] ) || ! defined( 'MAINWP_CHILD_DEBUG' ) || ( MAINWP_CHILD_DEBUG !== true ) ) {
|
||||
|
|
|
@ -1,30 +1,64 @@
|
|||
<?php
|
||||
/**
|
||||
* MainWP Child Plugin Pages
|
||||
*
|
||||
* This file handles all the pages & subpages for the
|
||||
* MainWP Child Plugin.
|
||||
*/
|
||||
|
||||
namespace MainWP\Child;
|
||||
|
||||
/**
|
||||
* Class MainWP_Pages
|
||||
*
|
||||
* @package MainWP\Child
|
||||
*/
|
||||
class MainWP_Pages {
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @var null Holds the Public static instance of MainWP_Child_Install.
|
||||
*/
|
||||
protected static $instance = null;
|
||||
|
||||
/**
|
||||
* @static
|
||||
* @var array MainWP Child Plugin subppages.
|
||||
*/
|
||||
public static $subPages;
|
||||
|
||||
/**
|
||||
* Whether or not MainWP Child Plugin subpages should be loaded. Default: false.
|
||||
*
|
||||
* @var bool true|false.
|
||||
*/
|
||||
public static $subPagesLoaded = false;
|
||||
|
||||
/**
|
||||
* @var null Branding Title.
|
||||
*/
|
||||
public static $brandingTitle = null;
|
||||
|
||||
/**
|
||||
* Method get_class_name()
|
||||
*
|
||||
* Get Class Name.
|
||||
*
|
||||
* @return object
|
||||
* @return string Class name.
|
||||
*/
|
||||
public static function get_class_name() {
|
||||
return __CLASS__;
|
||||
}
|
||||
|
||||
/**
|
||||
* MainWP_Pages constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
}
|
||||
|
||||
/**
|
||||
* Create public static instance of MainWP_Pages.
|
||||
*
|
||||
* @return MainWP_Pages|null
|
||||
*/
|
||||
public static function get_instance() {
|
||||
if ( null === self::$instance ) {
|
||||
self::$instance = new self();
|
||||
|
@ -33,6 +67,9 @@ class MainWP_Pages {
|
|||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set up constants with default values, unless user overrides.
|
||||
*/
|
||||
public function init() {
|
||||
add_action( 'admin_menu', array( &$this, 'admin_menu' ) );
|
||||
add_action( 'admin_head', array( &$this, 'admin_head' ) );
|
||||
|
@ -41,6 +78,13 @@ class MainWP_Pages {
|
|||
}
|
||||
|
||||
|
||||
/**
|
||||
* MainWP Child Plugin Admin Notice
|
||||
*
|
||||
* This notice is displayed immediately after installation or disconnection.
|
||||
*
|
||||
* @return string Admin message html.
|
||||
*/
|
||||
public function admin_notice() {
|
||||
// Admin Notice...
|
||||
if ( ! get_option( 'mainwp_child_pubkey' ) && MainWP_Helper::is_admin() && is_admin() ) {
|
||||
|
@ -67,6 +111,11 @@ class MainWP_Pages {
|
|||
MainWP_Child_Server_Information::render_warnings();
|
||||
}
|
||||
|
||||
/**
|
||||
* Admin menu settings.
|
||||
*
|
||||
* Add and remove Admin Menu Items dependant upon Branding settings.
|
||||
*/
|
||||
public function admin_menu() {
|
||||
$branding_opts = MainWP_Child_Branding::instance()->get_branding_options();
|
||||
$is_hide = isset( $branding_opts['hide'] ) ? $branding_opts['hide'] : '';
|
||||
|
@ -119,6 +168,12 @@ class MainWP_Pages {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Initiate MainWP Child Plugin pages.
|
||||
*
|
||||
* @param $child_menu_title New MainWP Child Plugin title defined in branding settings.
|
||||
* @param $child_page_title New MainWP Child Plugin page title defined in branding settings.
|
||||
*/
|
||||
private function init_pages( $child_menu_title, $child_page_title ) {
|
||||
|
||||
$settingsPage = add_submenu_page( 'options-general.php', $child_page_title, $child_menu_title, 'manage_options', 'mainwp_child_tab', array( &$this, 'render_pages' ) );
|
||||
|
@ -178,6 +233,13 @@ class MainWP_Pages {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* MainWP Child Plugin meta data.
|
||||
*
|
||||
* @param $plugin_meta Plugin meta.
|
||||
* @param $plugin_file Plugin file.
|
||||
* @return mixed The filtered value after all hooked functions are applied to it.
|
||||
*/
|
||||
public function plugin_row_meta( $plugin_meta, $plugin_file ) {
|
||||
global $mainWPChild;
|
||||
if ( $mainWPChild->plugin_slug !== $plugin_file ) {
|
||||
|
@ -186,6 +248,12 @@ class MainWP_Pages {
|
|||
return apply_filters( 'mainwp_child_plugin_row_meta', $plugin_meta, $plugin_file, $mainWPChild->plugin_slug );
|
||||
}
|
||||
|
||||
/**
|
||||
* Render MainWP Child Plugin pages.
|
||||
*
|
||||
* @param $shownPage Page that has been shown.
|
||||
* @return string Page html.
|
||||
*/
|
||||
public function render_pages( $shownPage ) {
|
||||
$shownPage = '';
|
||||
if ( isset( $_GET['tab'] ) ) {
|
||||
|
@ -252,6 +320,13 @@ class MainWP_Pages {
|
|||
self::render_footer();
|
||||
}
|
||||
|
||||
/**
|
||||
* Render page header.
|
||||
*
|
||||
* @param $shownPage Page shown.
|
||||
* @param bool $subpage Whether or not a subpage. Default: true.
|
||||
* @return string Header html.
|
||||
*/
|
||||
public static function render_header( $shownPage, $subpage = true ) {
|
||||
if ( isset( $_GET['tab'] ) ) {
|
||||
$shownPage = $_GET['tab'];
|
||||
|
@ -407,6 +482,11 @@ class MainWP_Pages {
|
|||
<?php
|
||||
}
|
||||
|
||||
/**
|
||||
* Render page footer.
|
||||
*
|
||||
* @return string Footer html.
|
||||
*/
|
||||
public static function render_footer() {
|
||||
?>
|
||||
</div>
|
||||
|
@ -414,7 +494,11 @@ class MainWP_Pages {
|
|||
<?php
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Render Admin Header.
|
||||
*
|
||||
* @return string Admin header html.
|
||||
*/
|
||||
public function admin_head() {
|
||||
if ( isset( $_GET['page'] ) && 'mainwp_child_tab' == $_GET['page'] ) {
|
||||
?>
|
||||
|
@ -442,6 +526,12 @@ class MainWP_Pages {
|
|||
<?php
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Render Connection Settings Sub Page.
|
||||
*
|
||||
* @return Connection Settings subpage html.
|
||||
*/
|
||||
public function render_settings() {
|
||||
if ( isset( $_POST['submit'] ) && isset( $_POST['nonce'] ) && wp_verify_nonce( $_POST['nonce'], 'child-settings' ) ) {
|
||||
if ( isset( $_POST['requireUniqueSecurityId'] ) ) {
|
||||
|
|
|
@ -1,4 +1,10 @@
|
|||
<?php
|
||||
/**
|
||||
* MainWP WordPress SEO
|
||||
*
|
||||
* The code is used for the MainWP WordPress SEO Extension.
|
||||
*/
|
||||
|
||||
/**
|
||||
* Credits
|
||||
*
|
||||
|
@ -16,9 +22,21 @@ use MainWP\Child\MainWP_Helper;
|
|||
|
||||
// phpcs:disable PSR1.Classes.ClassDeclaration, WordPress.WP.AlternativeFunctions -- to use external code, third party credit.
|
||||
|
||||
/**
|
||||
* Class MainWP_WordPress_SEO
|
||||
*/
|
||||
class MainWP_WordPress_SEO {
|
||||
/**
|
||||
* @static
|
||||
* @var null Public static instance of MainWP_WordPress_SEO.
|
||||
*/
|
||||
public static $instance = null;
|
||||
|
||||
/**
|
||||
* Create public static instance of MainWP_WordPress_SEO.
|
||||
*
|
||||
* @return MainWP_WordPress_SEO|null
|
||||
*/
|
||||
public static function instance() {
|
||||
if ( null === self::$instance ) {
|
||||
self::$instance = new self();
|
||||
|
@ -27,11 +45,22 @@ class MainWP_WordPress_SEO {
|
|||
return self::$instance;
|
||||
}
|
||||
|
||||
/**
|
||||
* MainWP_WordPress_SEO constructor.
|
||||
*/
|
||||
public function __construct() {
|
||||
|
||||
/** @var global $wpdb wbdb */
|
||||
global $wpdb;
|
||||
|
||||
add_action( 'mainwp_child_deactivation', array( $this, 'child_deactivation' ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* Removes option by name.
|
||||
*
|
||||
* @return bool True, if option is successfully deleted. False on failure.
|
||||
*/
|
||||
public function child_deactivation() {
|
||||
$dell_all = array();
|
||||
foreach ( $dell_all as $opt ) {
|
||||
|
@ -39,6 +68,9 @@ class MainWP_WordPress_SEO {
|
|||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* MainWP WordPress SEO import_settings $_POST action.
|
||||
*/
|
||||
public function action() {
|
||||
if ( ! class_exists( 'WPSEO_Admin' ) ) {
|
||||
$information['error'] = 'NO_WPSEO';
|
||||
|
@ -53,6 +85,11 @@ class MainWP_WordPress_SEO {
|
|||
MainWP_Helper::write( $information );
|
||||
}
|
||||
|
||||
/**
|
||||
* Import settings.
|
||||
*
|
||||
* @return array $information success[]|error[]
|
||||
*/
|
||||
public function import_settings() {
|
||||
if ( isset( $_POST['file_url'] ) ) {
|
||||
$file_url = base64_decode( $_POST['file_url'] ); // phpcs:ignore WordPress.PHP.DiscouragedPHPFunctions -- base64_encode function is used for begin reasons.
|
||||
|
@ -111,6 +148,13 @@ class MainWP_WordPress_SEO {
|
|||
MainWP_Helper::write( $information );
|
||||
}
|
||||
|
||||
/**
|
||||
* Import SEO settings.
|
||||
*
|
||||
* @param $file settings.ini file to import.
|
||||
* @return bool Return TRUE on success.
|
||||
* @throws Exception Trow an exception and return error message.
|
||||
*/
|
||||
public function import_seo_settings( $file ) {
|
||||
if ( ! empty( $file ) ) {
|
||||
$upload_dir = wp_upload_dir();
|
||||
|
@ -167,6 +211,12 @@ class MainWP_WordPress_SEO {
|
|||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse Column Score.
|
||||
*
|
||||
* @param $post_id Post ID.
|
||||
* @return string SEO Score.
|
||||
*/
|
||||
public function parse_column_score( $post_id ) {
|
||||
if ( '1' === WPSEO_Meta::get_value( 'meta-robots-noindex', $post_id ) ) {
|
||||
$rank = new WPSEO_Rank( WPSEO_Rank::NO_INDEX );
|
||||
|
@ -184,6 +234,12 @@ class MainWP_WordPress_SEO {
|
|||
return $this->render_score_indicator( $rank, $title );
|
||||
}
|
||||
|
||||
/**
|
||||
* Parse readability score.
|
||||
*
|
||||
* @param $post_id Post ID.
|
||||
* @return string Redability Score.
|
||||
*/
|
||||
public function parse_column_score_readability( $post_id ) {
|
||||
$score = (int) WPSEO_Meta::get_value( 'content_score', $post_id );
|
||||
$rank = WPSEO_Rank::from_numeric_score( $score );
|
||||
|
@ -191,6 +247,13 @@ class MainWP_WordPress_SEO {
|
|||
return $this->render_score_indicator( $rank );
|
||||
}
|
||||
|
||||
/**
|
||||
* Render Score Rank.
|
||||
*
|
||||
* @param $rank SEO Rank Score.
|
||||
* @param string $title Rank title.
|
||||
* @return string Return SEO Score html.
|
||||
*/
|
||||
private function render_score_indicator( $rank, $title = '' ) {
|
||||
if ( empty( $title ) ) {
|
||||
$title = $rank->get_label();
|
||||
|
|
|
@ -1,4 +1,9 @@
|
|||
<?php
|
||||
/**
|
||||
* MainWP Child Plugin
|
||||
*
|
||||
* Provides a secure connection between your MainWP Dashboard and your WordPress sites.
|
||||
*/
|
||||
/**
|
||||
* Plugin Name: MainWP Child
|
||||
* Plugin URI: https://mainwp.com/
|
||||
|
@ -10,24 +15,42 @@
|
|||
*/
|
||||
require_once ABSPATH . 'wp-includes' . DIRECTORY_SEPARATOR . 'version.php'; // Version information from WordPress.
|
||||
|
||||
/**
|
||||
* Define MainWP Child Plugin Debug Mode. Default: true.
|
||||
*/
|
||||
define( 'MAINWP_CHILD_DEBUG', true );
|
||||
|
||||
if ( ! defined( 'MAINWP_CHILD_FILE' ) ) {
|
||||
/**
|
||||
* Define MainWP Child Plugin absolute full path and filename of this file.
|
||||
*/
|
||||
define( 'MAINWP_CHILD_FILE', __FILE__ );
|
||||
}
|
||||
|
||||
if ( ! defined( 'MAINWP_CHILD_PLUGIN_DIR' ) ) {
|
||||
/**
|
||||
* Define MainWP Child Plugin Directory.
|
||||
*/
|
||||
define( 'MAINWP_CHILD_PLUGIN_DIR', plugin_dir_path( MAINWP_CHILD_FILE ) );
|
||||
}
|
||||
|
||||
if ( ! defined( 'MAINWP_CHILD_URL' ) ) {
|
||||
/**
|
||||
* Define MainWP Child Plugin URL.
|
||||
*/
|
||||
define( 'MAINWP_CHILD_URL', plugin_dir_url( MAINWP_CHILD_FILE ) );
|
||||
}
|
||||
|
||||
/**
|
||||
* MainWP Child Plugin Autoloader to load
|
||||
* all other class files.
|
||||
*
|
||||
* @param $class_name Name of file to load.
|
||||
*/
|
||||
function mainwp_child_autoload( $class_name ) {
|
||||
|
||||
if ( 0 === strpos( $class_name, 'MainWP\Child' ) ) {
|
||||
// trip the namespace prefix: MainWP\Child\ .
|
||||
// strip the namespace prefix: MainWP\Child\ .
|
||||
$class_name = substr( $class_name, 13 );
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue