updated plugin GP Premium version 1.11.2

This commit is contained in:
2020-08-13 14:53:39 +00:00
committed by Gitium
parent 3f0f8d3ac9
commit 885bbdd113
151 changed files with 11329 additions and 6954 deletions

View File

@ -1,6 +1,17 @@
<?php
defined( 'WPINC' ) or die;
/**
* This file has helper functions for the Site Library.
*
* @package GP Premium
*/
if ( ! defined( 'ABSPATH' ) ) {
exit; // No direct access, please.
}
/**
* Site Library helper class.
*/
class GeneratePress_Sites_Helper {
/**
@ -29,12 +40,15 @@ class GeneratePress_Sites_Helper {
*/
public static function get_instance() {
if ( ! isset( self::$instance ) ) {
self::$instance = new self;
self::$instance = new self();
}
return self::$instance;
}
/**
* Get it going.
*/
public function __construct() {
add_filter( 'upload_mimes', array( $this, 'mime_types' ) );
add_filter( 'wp_check_filetype_and_ext', array( $this, 'check_real_mime_type' ), 10, 4 );
@ -62,7 +76,7 @@ class GeneratePress_Sites_Helper {
*/
public static function includes() {
// Content Importer
// Content Importer.
if ( ! class_exists( 'WP_Importer' ) ) {
require ABSPATH . '/wp-admin/includes/class-wp-importer.php';
}
@ -74,12 +88,20 @@ class GeneratePress_Sites_Helper {
}
/**
* Get mapped term IDs.
*/
public static function get_mapped_term_ids() {
return ( array ) get_transient( 'generatepress_sites_mapped_term_ids' );
return (array) get_transient( 'generatepress_sites_mapped_term_ids' );
}
/**
* Get mapped post IDs.
*
* @param string $slug The slug of the post.
*/
public static function get_mapped_post_ids( $slug ) {
return ( array ) get_option( "generatepress_sites_mapped_ids_{$slug}", array() );
return (array) get_option( "generatepress_sites_mapped_ids_{$slug}", array() );
}
/**
@ -131,12 +153,12 @@ class GeneratePress_Sites_Helper {
$has_data = array(
'mods' => array(),
'options' => array()
'options' => array(),
);
foreach ( $theme_mods as $theme_mod ) {
if ( get_theme_mod( $theme_mod ) ) {
$has_data['mods'][$theme_mod] = get_theme_mod( $theme_mod );
$has_data['mods'][ $theme_mod ] = get_theme_mod( $theme_mod );
}
}
@ -160,7 +182,7 @@ class GeneratePress_Sites_Helper {
}
}
$has_data['options'][$setting] = get_option( $setting );
$has_data['options'][ $setting ] = get_option( $setting );
}
}
@ -175,11 +197,11 @@ class GeneratePress_Sites_Helper {
* Imports our content and custom CSS.
*
* @since 1.6
*
* @param string $path
* @param string $path Path to the file.
* @param string $slug File slug.
*/
public static function import_xml( $path, $slug ) {
$options = array(
$options = array(
'fetch_attachments' => true,
'default_author' => 0,
);
@ -211,9 +233,6 @@ class GeneratePress_Sites_Helper {
// Page builders need so much extra work.
self::update_page_builder_content();
// Log our content
//self::log( $logger );
}
/**
@ -227,11 +246,14 @@ class GeneratePress_Sites_Helper {
* @return array
*/
public static function check_for_pro_plugins() {
return apply_filters( 'generate_sites_pro_plugins', array(
'beaver-builder-lite-version/fl-builder.php' => 'bb-plugin/fl-builder.php',
'ultimate-addons-for-beaver-builder-lite/bb-ultimate-addon.php' => 'bb-ultimate-addon/bb-ultimate-addon.php',
'powerpack-addon-for-beaver-builder/bb-powerpack-lite.php' => 'bbpowerpack/bb-powerpack.php',
) );
return apply_filters(
'generate_sites_pro_plugins',
array(
'beaver-builder-lite-version/fl-builder.php' => 'bb-plugin/fl-builder.php',
'ultimate-addons-for-beaver-builder-lite/bb-ultimate-addon.php' => 'bb-ultimate-addon/bb-ultimate-addon.php',
'powerpack-addon-for-beaver-builder/bb-powerpack-lite.php' => 'bbpowerpack/bb-powerpack.php',
)
);
}
/**
@ -239,14 +261,14 @@ class GeneratePress_Sites_Helper {
*
* @since 1.6
*
* @param string $plugin
* @param string $plugin The plugin to check for.
*/
public static function is_plugin_installed( $plugin ) {
$pro_plugins = self::check_for_pro_plugins();
// Check to see if this plugin has a pro version.
if ( array_key_exists( $plugin, $pro_plugins ) ) {
if ( file_exists( WP_PLUGIN_DIR . '/' . $pro_plugins[$plugin] ) ) {
if ( file_exists( WP_PLUGIN_DIR . '/' . $pro_plugins[ $plugin ] ) ) {
return true;
}
}
@ -264,9 +286,9 @@ class GeneratePress_Sites_Helper {
*
* @since 1.6
*
* @param array $response Attachment response.
* @param array $response Attachment response.
* @param object $attachment Attachment object.
* @param array $meta Attachment meta data.
* @param array $meta Attachment meta data.
*/
public static function add_svg_image_support( $response, $attachment, $meta ) {
if ( ! function_exists( 'simplexml_load_file' ) ) {
@ -337,9 +359,9 @@ class GeneratePress_Sites_Helper {
$data = new stdClass();
if ( ! function_exists( 'media_handle_sideload' ) ) {
require_once( ABSPATH . 'wp-admin/includes/media.php' );
require_once( ABSPATH . 'wp-admin/includes/file.php' );
require_once( ABSPATH . 'wp-admin/includes/image.php' );
require_once ABSPATH . 'wp-admin/includes/media.php';
require_once ABSPATH . 'wp-admin/includes/file.php';
require_once ABSPATH . 'wp-admin/includes/image.php';
}
if ( ! empty( $file ) ) {
@ -362,22 +384,22 @@ class GeneratePress_Sites_Helper {
// If error storing permanently, unlink.
if ( is_wp_error( $id ) ) {
@unlink( $file_array['tmp_name'] );
@unlink( $file_array['tmp_name'] ); // phpcs:ignore
return $id;
}
// Build the object to return.
$meta = wp_get_attachment_metadata( $id );
$data->attachment_id = $id;
$data->url = wp_get_attachment_url( $id );
$data->thumbnail_url = wp_get_attachment_thumb_url( $id );
$meta = wp_get_attachment_metadata( $id );
$data->attachment_id = $id;
$data->url = wp_get_attachment_url( $id );
$data->thumbnail_url = wp_get_attachment_thumb_url( $id );
if ( isset( $meta['height'] ) ) {
$data->height = $meta['height'];
$data->height = $meta['height'];
}
if ( isset( $meta['width'] ) ) {
$data->width = $meta['width'];
$data->width = $meta['width'];
}
}
@ -390,7 +412,7 @@ class GeneratePress_Sites_Helper {
*
* @since 1.6
*
* @param array Incoming locations.
* @param array $locations Incoming locations.
*/
public static function set_nav_menu_locations( $locations = array() ) {
$menu_locations = array();
@ -405,8 +427,8 @@ class GeneratePress_Sites_Helper {
continue;
}
$menu_locations[$menu] = $term_ids[$value];
self::log( $value . ' -> ' . $term_ids[$value] );
$menu_locations[ $menu ] = $term_ids[ $value ];
self::log( $value . ' -> ' . $term_ids[ $value ] );
}
set_theme_mod( 'nav_menu_locations', $menu_locations );
@ -418,7 +440,8 @@ class GeneratePress_Sites_Helper {
*
* @since 1.6
*
* @param array Incoming locations.
* @param array $locations Incoming locations.
* @param string $slug Page Header slug.
*/
public static function set_global_page_header_locations( $locations = array(), $slug ) {
$new_locations = array();
@ -428,13 +451,13 @@ class GeneratePress_Sites_Helper {
if ( isset( $locations ) && ! empty( $locations ) ) {
self::log( '== Start mapping global page headers ==' );
foreach( $locations as $key => $value ) {
foreach ( $locations as $key => $value ) {
if ( empty( $value ) ) {
continue;
}
$new_locations[$key] = $post_ids[$value];
self::log( $value . ' -> ' . $post_ids[$value] );
$new_locations[ $key ] = $post_ids[ $value ];
self::log( $value . ' -> ' . $post_ids[ $value ] );
}
update_option( 'generate_page_header_global_locations', $new_locations );
@ -446,7 +469,8 @@ class GeneratePress_Sites_Helper {
*
* @since 1.6
*
* @param array Incoming locations.
* @param array $headers Incoming locations.
* @param string $slug Post slug.
*/
public static function set_page_headers( $headers = array(), $slug ) {
$new_headers = array();
@ -457,8 +481,8 @@ class GeneratePress_Sites_Helper {
self::log( '== Start mapping individual page headers ==' );
foreach ( $headers as $post_id => $header_id ) {
update_post_meta( $post_ids[$post_id], '_generate-select-page-header', $post_ids[$header_id] );
self::log( $header_id . ' -> ' . $post_ids[$header_id] );
update_post_meta( $post_ids[ $post_id ], '_generate-select-page-header', $post_ids[ $header_id ] );
self::log( $header_id . ' -> ' . $post_ids[ $header_id ] );
}
}
}
@ -468,8 +492,9 @@ class GeneratePress_Sites_Helper {
*
* @since 1.6
*
* @param string Name of the option to update.
* @param string Title of the page.
* @param string $name Name of the option to update.
* @param string $value Title of the page.
* @param string $slug Slug of the page.
*/
public static function set_reading_pages( $name, $value, $slug ) {
if ( empty( $value ) ) {
@ -481,8 +506,8 @@ class GeneratePress_Sites_Helper {
// Get import data, with new menu IDs.
$post_ids = self::get_mapped_post_ids( $slug );
update_option( $name, $post_ids[$value] );
self::log( $value . ' -> ' . $post_ids[$value] );
update_option( $name, $post_ids[ $value ] );
self::log( $value . ' -> ' . $post_ids[ $value ] );
}
/**
@ -490,8 +515,9 @@ class GeneratePress_Sites_Helper {
*
* @since 1.6
*
* @param string Name of the option to update.
* @param string Title of the page.
* @param string $name Name of the option to update.
* @param string $value Title of the page.
* @param string $slug Slug of the page.
*/
public static function set_woocommerce_pages( $name, $value, $slug ) {
if ( empty( $value ) ) {
@ -502,8 +528,8 @@ class GeneratePress_Sites_Helper {
$post_ids = self::get_mapped_post_ids( $slug );
update_option( $name, $post_ids[$value] );
self::log( $value . ' -> ' . $post_ids[$value] );
update_option( $name, $post_ids[ $value ] );
self::log( $value . ' -> ' . $post_ids[ $value ] );
}
/**
@ -540,7 +566,8 @@ class GeneratePress_Sites_Helper {
*
* @since 1.7
*
* @param array Incoming locations.
* @param array $locations Incoming locations.
* @param string $slug Element slug.
*/
public static function set_element_locations( $locations = array(), $slug ) {
$post_ids = self::get_mapped_post_ids( $slug );
@ -548,22 +575,22 @@ class GeneratePress_Sites_Helper {
if ( isset( $locations ) && ! empty( $locations ) ) {
self::log( '== Start mapping element locations ==' );
foreach( $locations as $key => $value ) {
foreach ( $locations as $key => $value ) {
$new_locations = array();
if ( empty( $value ) ) {
continue;
}
foreach ( ( array ) $value as $data ) {
foreach ( (array) $value as $data ) {
if ( $data['object'] ) {
self::log( $data['object'] . ' -> ' . $post_ids[$data['object']] );
$data['object'] = $post_ids[$data['object']];
self::log( $data['object'] . ' -> ' . $post_ids[ $data['object'] ] );
$data['object'] = $post_ids[ $data['object'] ];
}
$new_locations[] = $data;
}
update_post_meta( $post_ids[$key], '_generate_element_display_conditions', $new_locations );
update_post_meta( $post_ids[ $key ], '_generate_element_display_conditions', $new_locations );
}
}
}
@ -573,7 +600,8 @@ class GeneratePress_Sites_Helper {
*
* @since 1.7
*
* @param array Incoming locations.
* @param array $locations Incoming locations.
* @param string $slug Element slug.
*/
public static function set_element_exclusions( $locations = array(), $slug ) {
$post_ids = self::get_mapped_post_ids( $slug );
@ -581,22 +609,22 @@ class GeneratePress_Sites_Helper {
if ( isset( $locations ) && ! empty( $locations ) ) {
self::log( '== Start mapping element exclusions ==' );
foreach( $locations as $key => $value ) {
foreach ( $locations as $key => $value ) {
$new_locations = array();
if ( empty( $value ) ) {
continue;
}
foreach ( ( array ) $value as $data ) {
foreach ( (array) $value as $data ) {
if ( $data['object'] ) {
self::log( $data['object'] . ' -> ' . $post_ids[$data['object']] );
$data['object'] = $post_ids[$data['object']];
self::log( $data['object'] . ' -> ' . $post_ids[ $data['object'] ] );
$data['object'] = $post_ids[ $data['object'] ];
}
$new_locations[] = $data;
}
update_post_meta( $post_ids[$key], '_generate_element_exclude_conditions', $new_locations );
update_post_meta( $post_ids[ $key ], '_generate_element_exclude_conditions', $new_locations );
}
}
}
@ -605,16 +633,15 @@ class GeneratePress_Sites_Helper {
* Update menu URLs.
*
* @since 1.7.3
*
* @param string Preview URL
* @param string $url Preview URL.
*/
public static function update_menu_urls( $url ) {
$args = array (
'post_type' => 'nav_menu_item',
'fields' => 'ids',
$args = array(
'post_type' => 'nav_menu_item',
'fields' => 'ids',
'no_found_rows' => true,
'post_status' => 'any',
'numberposts' => 50,
'post_status' => 'any',
'numberposts' => 50,
);
$items = get_posts( $args );
@ -639,16 +666,17 @@ class GeneratePress_Sites_Helper {
*
* @since 1.6
*
* @param array Existing types.
* @param array $mimes Existing types.
* @return array Merged types.
*/
public static function mime_types( $mimes ) {
$mimes = array_merge(
$mimes, array(
$mimes,
array(
'xml' => 'text/xml',
'wie' => 'text/plain',
'svg' => 'image/svg+xml',
'svgz' => 'image/svg+xml'
'svgz' => 'image/svg+xml',
)
);
@ -662,12 +690,10 @@ class GeneratePress_Sites_Helper {
*
* @since 1.8
*
* @param array $wp_check_filetype_and_ext File data array containing 'ext', 'type', and
* 'proper_filename' keys.
* @param string $file Full path to the file.
* @param string $filename The name of the file (may differ from $file due to
* $file being in a tmp directory).
* @param array $mimes Key is the file extension with value as the mime type.
* @param array $defaults Default file types.
* @param string $file Full path to the file.
* @param string $filename The name of the file (may differ from $file due to $file being in a tmp directory).
* @param array $mimes Key is the file extension with value as the mime type.
*/
public static function check_real_mime_type( $defaults, $file, $filename, $mimes ) {
if ( 'content.xml' === $filename ) {
@ -688,30 +714,30 @@ class GeneratePress_Sites_Helper {
*
* @since 1.6
*
* @param string URL of the file.
* @param string $file URL of the file.
* @return array
*/
public static function download_file( $file ) {
// Gives us access to the download_url() and wp_handle_sideload() functions
require_once( ABSPATH . 'wp-admin/includes/file.php' );
// Gives us access to the download_url() and wp_handle_sideload() functions.
require_once ABSPATH . 'wp-admin/includes/file.php';
// URL to the WordPress logo
// URL to the WordPress logo.
$url = $file;
$timeout_seconds = 10;
// Download file to temp dir
// Download file to temp dir.
$temp_file = download_url( $url, $timeout_seconds );
if ( is_wp_error( $temp_file ) ) {
return array(
'success' => false,
'data' => $temp_file->get_error_message()
'data' => $temp_file->get_error_message(),
);
}
// Array based on $_FILE as seen in PHP file uploads
// Array based on $_FILE as seen in PHP file uploads.
$file = array(
'name' => basename( $url ),
'tmp_name' => $temp_file,
@ -724,7 +750,7 @@ class GeneratePress_Sites_Helper {
'test_size' => true,
);
// Move the temporary file into the uploads directory
// Move the temporary file into the uploads directory.
$results = wp_handle_sideload( $file, $overrides );
if ( empty( $results['error'] ) ) {
@ -750,7 +776,7 @@ class GeneratePress_Sites_Helper {
*
* @since 1.6
*
* @param string URL of the file.
* @param string $url URL of the file.
* @return array
*/
public static function get_options( $url ) {
@ -768,7 +794,7 @@ class GeneratePress_Sites_Helper {
*
* @since 1.6
*
* @param string URL of the file.
* @param string $url URL of the file.
* @return bool
*/
public static function file_exists( $url ) {
@ -779,7 +805,7 @@ class GeneratePress_Sites_Helper {
return false;
}
return strlen( $response['body'] ) > 100 && ( '200' == $response['response']['code'] || '301' == $response['response']['code'] ) ? true : false;
return strlen( $response['body'] ) > 100 && ( '200' === (string) $response['response']['code'] || '301' === (string) $response['response']['code'] ) ? true : false;
}
/**
@ -795,9 +821,9 @@ class GeneratePress_Sites_Helper {
}
if ( is_array( $log ) || is_object( $log ) ) {
error_log( print_r( $log, true ) );
error_log( print_r( $log, true ) ); // phpcs:ignore -- Needed to log events.
} else {
error_log( $log );
error_log( $log ); // phpcs:ignore -- Needed to log events.
}
}
@ -814,18 +840,18 @@ class GeneratePress_Sites_Helper {
'fields' => 'ids',
'no_found_rows' => true,
'post_status' => 'publish',
'numberposts' => -1,
'numberposts' => -1,
'meta_query' => array(
'relation' => 'OR',
array(
'key' => '_fl_builder_data',
'compare' => 'EXISTS',
),
array(
'key' => '_elementor_data',
'compare' => 'EXISTS',
)
)
'key' => '_fl_builder_data',
'compare' => 'EXISTS',
),
array(
'key' => '_elementor_data',
'compare' => 'EXISTS',
),
),
);
$posts = get_posts( $args );
@ -948,40 +974,16 @@ class GeneratePress_Sites_Helper {
public static function loading_icon() {
?>
<svg width="44" height="44" viewBox="0 0 44 44" xmlns="http://www.w3.org/2000/svg" stroke="#000">
<g fill="none" fill-rule="evenodd" stroke-width="2">
<circle cx="22" cy="22" r="1">
<animate attributeName="r"
begin="0s" dur="1.8s"
values="1; 20"
calcMode="spline"
keyTimes="0; 1"
keySplines="0.165, 0.84, 0.44, 1"
repeatCount="indefinite" />
<animate attributeName="stroke-opacity"
begin="0s" dur="1.8s"
values="1; 0"
calcMode="spline"
keyTimes="0; 1"
keySplines="0.3, 0.61, 0.355, 1"
repeatCount="indefinite" />
</circle>
<circle cx="22" cy="22" r="1">
<animate attributeName="r"
begin="-0.9s" dur="1.8s"
values="1; 20"
calcMode="spline"
keyTimes="0; 1"
keySplines="0.165, 0.84, 0.44, 1"
repeatCount="indefinite" />
<animate attributeName="stroke-opacity"
begin="-0.9s" dur="1.8s"
values="1; 0"
calcMode="spline"
keyTimes="0; 1"
keySplines="0.3, 0.61, 0.355, 1"
repeatCount="indefinite" />
</circle>
</g>
<g fill="none" fill-rule="evenodd" stroke-width="2">
<circle cx="22" cy="22" r="1">
<animate attributeName="r" begin="0s" dur="1.8s" values="1; 20" calcMode="spline" keyTimes="0; 1" keySplines="0.165, 0.84, 0.44, 1" repeatCount="indefinite" />
<animate attributeName="stroke-opacity" begin="0s" dur="1.8s" values="1; 0" calcMode="spline" keyTimes="0; 1" keySplines="0.3, 0.61, 0.355, 1" repeatCount="indefinite" />
</circle>
<circle cx="22" cy="22" r="1">
<animate attributeName="r" begin="-0.9s" dur="1.8s" values="1; 20" calcMode="spline" keyTimes="0; 1" keySplines="0.165, 0.84, 0.44, 1" repeatCount="indefinite" />
<animate attributeName="stroke-opacity" begin="-0.9s" dur="1.8s" values="1; 0" calcMode="spline" keyTimes="0; 1" keySplines="0.3, 0.61, 0.355, 1" repeatCount="indefinite" />
</circle>
</g>
</svg>
<?php
}