Edit File by line

Deprecated: str_replace(): Passing null to parameter #2 ($replace) of type array|string is deprecated in /home/sportsfever/public_html/filemanger/function.php on line 93
/home/sportsfe.../httpdocs/clone/wp-conte.../plugins/themify-.../classes
File: class-themify-builder-revisions.php
<?php
[0] Fix | Delete
[1] Fix | Delete
/**
[2] Fix | Delete
* The file that enable builder revisions.
[3] Fix | Delete
*
[4] Fix | Delete
* Themify_Builder_Revisions class provide hooks and filter to WP Revisions API
[5] Fix | Delete
* This enable builder being tracked by WP Revisions and able to restore
[6] Fix | Delete
* the revision for builder.
[7] Fix | Delete
*
[8] Fix | Delete
*
[9] Fix | Delete
* @package Themify_Builder
[10] Fix | Delete
* @subpackage Themify_Builder/classes
[11] Fix | Delete
*/
[12] Fix | Delete
[13] Fix | Delete
/**
[14] Fix | Delete
* The Builder Revision class.
[15] Fix | Delete
*
[16] Fix | Delete
* This is used to handle all revisions operation and method.
[17] Fix | Delete
*
[18] Fix | Delete
*
[19] Fix | Delete
* @package Themify_Builder
[20] Fix | Delete
* @subpackage Themify_Builder/classes
[21] Fix | Delete
* @author Themify
[22] Fix | Delete
*/
[23] Fix | Delete
final class Themify_Builder_Revisions {
[24] Fix | Delete
[25] Fix | Delete
private const REVISION_LIMIT = 50;
[26] Fix | Delete
[27] Fix | Delete
/**
[28] Fix | Delete
* Constructor.
[29] Fix | Delete
*
[30] Fix | Delete
* @param object Themify_Builder $builder
[31] Fix | Delete
*/
[32] Fix | Delete
public static function init() {
[33] Fix | Delete
[34] Fix | Delete
$ajax_events = array(
[35] Fix | Delete
'load_revision_lists',
[36] Fix | Delete
'save_revision',
[37] Fix | Delete
'restore_revision_page',
[38] Fix | Delete
'delete_revision'
[39] Fix | Delete
);
[40] Fix | Delete
[41] Fix | Delete
foreach ($ajax_events as $ajax_event) {
[42] Fix | Delete
add_action('wp_ajax_tb_' . $ajax_event, array(__CLASS__, $ajax_event));
[43] Fix | Delete
}
[44] Fix | Delete
[45] Fix | Delete
add_filter('_wp_post_revision_fields', array(__CLASS__, 'post_revision_fields'), 10, 2);
[46] Fix | Delete
[47] Fix | Delete
add_action('wp_restore_post_revision', array(__CLASS__, 'restore_revision'), 10, 2);
[48] Fix | Delete
}
[49] Fix | Delete
[50] Fix | Delete
/**
[51] Fix | Delete
* Ajax Get all post revisions list.
[52] Fix | Delete
*
[53] Fix | Delete
* @access public
[54] Fix | Delete
*/
[55] Fix | Delete
public static function load_revision_lists() {
[56] Fix | Delete
check_ajax_referer('tf_nonce', 'nonce');
[57] Fix | Delete
if (!empty( $_POST['bid'] ) && current_user_can( 'read_post', $_POST['bid'] ) ) {
[58] Fix | Delete
$post_id = (int) $_POST['bid'];
[59] Fix | Delete
$revisions = wp_get_post_revisions($post_id, array(
[60] Fix | Delete
'posts_per_page' => self::REVISION_LIMIT,
[61] Fix | Delete
));
[62] Fix | Delete
$can_edit_post = $post_id === 0 ? true : current_user_can('edit_post', $post_id);
[63] Fix | Delete
include THEMIFY_BUILDER_INCLUDES_DIR . '/tpl/tmpl-revisions.php';
[64] Fix | Delete
}
[65] Fix | Delete
wp_die();
[66] Fix | Delete
}
[67] Fix | Delete
[68] Fix | Delete
/**
[69] Fix | Delete
* Hook themify builder field to revisions fields.
[70] Fix | Delete
*
[71] Fix | Delete
* @access public
[72] Fix | Delete
* @param array $fields
[73] Fix | Delete
* @return array
[74] Fix | Delete
*/
[75] Fix | Delete
public static function post_revision_fields(array $fields, $post):array {
[76] Fix | Delete
if (function_exists('wp_print_revision_templates')) {
[77] Fix | Delete
$fields[ThemifyBuilder_Data_Manager::META_KEY] = esc_html__('Themify Builder', 'themify');
[78] Fix | Delete
add_filter('_wp_post_revision_field__themify_builder_settings_json', array(__CLASS__, 'post_revision_field'), 10, 4);
[79] Fix | Delete
}
[80] Fix | Delete
return $fields;
[81] Fix | Delete
}
[82] Fix | Delete
[83] Fix | Delete
/**
[84] Fix | Delete
* Render the builder output in revision compare slider.
[85] Fix | Delete
*
[86] Fix | Delete
* @access public
[87] Fix | Delete
* @param string $value
[88] Fix | Delete
* @param string $field
[89] Fix | Delete
* @return string
[90] Fix | Delete
*/
[91] Fix | Delete
public static function post_revision_field($value, $field, $revision, $type) {
[92] Fix | Delete
if (is_object($revision)) {
[93] Fix | Delete
$builder_data = ThemifyBuilder_Data_Manager::get_data($revision->ID);
[94] Fix | Delete
[95] Fix | Delete
if (!empty($builder_data)) {
[96] Fix | Delete
return Themify_Builder_Component_Module::retrieve_template('builder-output.php', array('builder_output' => $builder_data, 'builder_id' => $revision->ID), THEMIFY_BUILDER_TEMPLATES_DIR, '', false);
[97] Fix | Delete
}
[98] Fix | Delete
}
[99] Fix | Delete
}
[100] Fix | Delete
[101] Fix | Delete
/**
[102] Fix | Delete
* Ajax save revision.
[103] Fix | Delete
*
[104] Fix | Delete
* @access public
[105] Fix | Delete
*/
[106] Fix | Delete
public static function save_revision() {
[107] Fix | Delete
check_ajax_referer('tf_nonce', 'nonce');
[108] Fix | Delete
/* set a default limit for revisions */
[109] Fix | Delete
if (!defined('WP_POST_REVISIONS')) {
[110] Fix | Delete
define('WP_POST_REVISIONS', self::REVISION_LIMIT);
[111] Fix | Delete
}
[112] Fix | Delete
if (isset($_POST['data'])) {
[113] Fix | Delete
$data = stripslashes_deep($_POST['data']);
[114] Fix | Delete
} elseif (isset($_FILES['data'])) {
[115] Fix | Delete
$data = file_get_contents($_FILES['data']['tmp_name']);
[116] Fix | Delete
}
[117] Fix | Delete
if (!empty($data)) {
[118] Fix | Delete
$data = json_decode($data, true);
[119] Fix | Delete
if (!empty($data)) {
[120] Fix | Delete
$post_id = (int) $_POST['bid'];
[121] Fix | Delete
$post = get_post($post_id);
[122] Fix | Delete
$rev_comment = !empty($_POST['rev_comment']) ? sanitize_text_field($_POST['rev_comment']) : '';
[123] Fix | Delete
if (!current_user_can('edit_post', $post_id)){
[124] Fix | Delete
wp_send_json_error(esc_html__('Error. You do not have access to save revision.', 'themify'));
[125] Fix | Delete
}
[126] Fix | Delete
if (!self::is_revision_enabled($post)){
[127] Fix | Delete
wp_send_json_error(esc_html__('Error. The revision is not enable in this post or has been reach the revision post limit.', 'themify'));
[128] Fix | Delete
}
[129] Fix | Delete
if (is_object($post)) {
[130] Fix | Delete
$post = get_object_vars($post);
[131] Fix | Delete
}
[132] Fix | Delete
unset($post['post_modified'], $post['post_modified_gmt']);
[133] Fix | Delete
$new_revision_id = _wp_put_post_revision($post);
[134] Fix | Delete
$results = array();
[135] Fix | Delete
if (!is_wp_error($new_revision_id)) {
[136] Fix | Delete
if (!empty($rev_comment)) {
[137] Fix | Delete
update_metadata('post', $new_revision_id, '_builder_custom_rev_comment', $rev_comment);
[138] Fix | Delete
}
[139] Fix | Delete
$custom_css = isset($_POST['custom_css']) ? $_POST['custom_css'] : null;
[140] Fix | Delete
$results = ThemifyBuilder_Data_Manager::save_data($data, $new_revision_id, $_POST['sourceEditor'], $custom_css);
[141] Fix | Delete
}
[142] Fix | Delete
if (!empty($results['mid'])) {
[143] Fix | Delete
wp_send_json_success($new_revision_id);
[144] Fix | Delete
}
[145] Fix | Delete
if (!is_wp_error($new_revision_id)) {
[146] Fix | Delete
wp_delete_post_revision($new_revision_id);
[147] Fix | Delete
}
[148] Fix | Delete
wp_send_json_error(esc_html__('Cannot save revision, please try again.', 'themify'));
[149] Fix | Delete
}
[150] Fix | Delete
wp_send_json_success();
[151] Fix | Delete
}
[152] Fix | Delete
wp_send_json_error(esc_html__('Cannot save revision, please try again.', 'themify'));
[153] Fix | Delete
}
[154] Fix | Delete
[155] Fix | Delete
/**
[156] Fix | Delete
* Hook to restore revision.
[157] Fix | Delete
*
[158] Fix | Delete
* @access public
[159] Fix | Delete
* @param int $post_id
[160] Fix | Delete
* @param int $rev_id
[161] Fix | Delete
*/
[162] Fix | Delete
public static function restore_revision($post_id, $rev_id) {
[163] Fix | Delete
$builder_data = ThemifyBuilder_Data_Manager::get_data($rev_id);
[164] Fix | Delete
if (!empty($builder_data)) {
[165] Fix | Delete
ThemifyBuilder_Data_Manager::save_data($builder_data, $post_id);
[166] Fix | Delete
}
[167] Fix | Delete
}
[168] Fix | Delete
[169] Fix | Delete
/**
[170] Fix | Delete
* Ajax restore revision.
[171] Fix | Delete
*
[172] Fix | Delete
* @access public
[173] Fix | Delete
*/
[174] Fix | Delete
public static function restore_revision_page() {
[175] Fix | Delete
check_ajax_referer('tf_nonce', 'nonce');
[176] Fix | Delete
$rev_id = (int) $_POST['revid'];
[177] Fix | Delete
$revision = wp_get_post_revision($rev_id);
[178] Fix | Delete
[179] Fix | Delete
if (!current_user_can('edit_post', $revision->post_parent)) {
[180] Fix | Delete
wp_send_json_error(esc_html__('Error. You do not have access to restore revision.', 'themify'));
[181] Fix | Delete
}
[182] Fix | Delete
[183] Fix | Delete
if ($revision) {
[184] Fix | Delete
wp_send_json(array('builder_data' => ThemifyBuilder_Data_Manager::get_data($rev_id), 'custom_css' => get_post_meta($rev_id, 'tbp_custom_css', true)));
[185] Fix | Delete
}
[186] Fix | Delete
wp_send_json_error(esc_html__('Revision post is not found or invalid ID', 'themify'));
[187] Fix | Delete
}
[188] Fix | Delete
[189] Fix | Delete
/**
[190] Fix | Delete
* Ajax delete revision.
[191] Fix | Delete
*
[192] Fix | Delete
* @access public
[193] Fix | Delete
* @return json
[194] Fix | Delete
*/
[195] Fix | Delete
public static function delete_revision() {
[196] Fix | Delete
check_ajax_referer('tf_nonce', 'nonce');
[197] Fix | Delete
$rev_id = (int) $_POST['revid'];
[198] Fix | Delete
$revision = wp_get_post_revision($rev_id);
[199] Fix | Delete
if (!current_user_can('edit_post', $revision->post_parent)) {
[200] Fix | Delete
wp_send_json_error(esc_html__('Error. You do not have access to delete revision.', 'themify'));
[201] Fix | Delete
}
[202] Fix | Delete
[203] Fix | Delete
$delete = wp_delete_post_revision($rev_id);
[204] Fix | Delete
if (!is_wp_error($delete)) {
[205] Fix | Delete
wp_send_json_success($rev_id);
[206] Fix | Delete
}
[207] Fix | Delete
wp_send_json_error(esc_html__('Unable to delete this revision, please try again!', 'themify'));
[208] Fix | Delete
[209] Fix | Delete
}
[210] Fix | Delete
[211] Fix | Delete
/**
[212] Fix | Delete
* create builder revision
[213] Fix | Delete
*
[214] Fix | Delete
* @access public
[215] Fix | Delete
* @param int $post_id
[216] Fix | Delete
* @param object $post
[217] Fix | Delete
*/
[218] Fix | Delete
public static function create_revision($post_id, $builder_data, $action) {
[219] Fix | Delete
if (!wp_is_post_revision($post_id)) {
[220] Fix | Delete
$post = get_post($post_id);
[221] Fix | Delete
if (!empty($post) && 'auto-draft' !== $post->post_status && wp_revisions_enabled($post) && post_type_supports($post->post_type, 'revisions')) {
[222] Fix | Delete
unset($post->post_modified, $post->post_modified_gmt);
[223] Fix | Delete
$rev_id = _wp_put_post_revision($post);
[224] Fix | Delete
if (!is_wp_error($rev_id)) {
[225] Fix | Delete
if (empty($builder_data)) {
[226] Fix | Delete
$builder_data = array();
[227] Fix | Delete
}
[228] Fix | Delete
ThemifyBuilder_Data_Manager::save_data($builder_data, $rev_id, $action);
[229] Fix | Delete
return $rev_id;
[230] Fix | Delete
}
[231] Fix | Delete
}
[232] Fix | Delete
}
[233] Fix | Delete
return false;
[234] Fix | Delete
}
[235] Fix | Delete
[236] Fix | Delete
/**
[237] Fix | Delete
* Check if revision has builder data.
[238] Fix | Delete
*
[239] Fix | Delete
* @access public
[240] Fix | Delete
* @param int $post_id
[241] Fix | Delete
* @return boolean
[242] Fix | Delete
*/
[243] Fix | Delete
public static function check_has_builder($post_id):bool {
[244] Fix | Delete
$builder_data = get_metadata('post', $post_id, ThemifyBuilder_Data_Manager::META_KEY, true);
[245] Fix | Delete
return !empty($builder_data);
[246] Fix | Delete
}
[247] Fix | Delete
[248] Fix | Delete
public static function is_revision_enabled($post):bool {
[249] Fix | Delete
$p = get_post($post);
[250] Fix | Delete
return wp_revisions_enabled($p) && post_type_supports($p->post_type, 'revisions');
[251] Fix | Delete
}
[252] Fix | Delete
}
[253] Fix | Delete
[254] Fix | Delete
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function