Skip to content

Commit

Permalink
Merge pull request #119 from HeyMehedi/demo-url-replace
Browse files Browse the repository at this point in the history
Demo URL Replace
  • Loading branch information
HeyMehedi authored Oct 15, 2024
2 parents 9cb0ea3 + 4551e46 commit 40fdafd
Show file tree
Hide file tree
Showing 9 changed files with 48 additions and 19 deletions.
11 changes: 11 additions & 0 deletions app/FullTemplate/FullTemplate.php
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,8 @@ private function __construct() {
add_action( 'delete_attachment', [$this, 'delete_templatiq_images'] );
add_filter( 'wp_php_error_message', [$this, 'php_error_message'], 10, 2 );
add_filter( 'wp_import_post_data_processed', [$this, 'wp_slash_after_xml_import'], 99, 2 );

add_filter( 'templatiq_wxr_importer.pre_process.post', [$this, 'replace_hard_coded_demo_url'], 10 );
}

private function includes() {
Expand Down Expand Up @@ -104,4 +106,13 @@ public function php_error_message( $message, $error ) {
public function wp_slash_after_xml_import( $postdata, $data ) {
return wp_slash( $postdata );
}

public function replace_hard_coded_demo_url( $data ) {
if ( ! empty( $data['post_content'] ) ) {
$site_url = templatiq_get_site_data( 'site_url' );
$data['post_content'] = str_replace( $site_url, site_url(), $data['post_content'] );
}

return $data;
}
}
4 changes: 2 additions & 2 deletions app/FullTemplate/ImportComplete.php
Original file line number Diff line number Diff line change
Expand Up @@ -36,8 +36,8 @@ public function update_menu_links() {
return;
}

$demo_url = templatiq_get_site_data( 'templatiq-site-url' );
$site_url = site_url() . '/';
$demo_url = templatiq_get_site_data( 'site_url' );
$site_url = site_url();

foreach ( $menu_ref as $menu_id ) {
$post = get_post( $menu_id );
Expand Down
4 changes: 1 addition & 3 deletions app/FullTemplate/Importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -403,9 +403,7 @@ public function delete_imported_posts( $post_id = 0 ) {
wp_delete_post( $post_id, true );
}

if ( defined( 'WP_CLI' ) ) {
WP_CLI::line( $message );
} elseif ( wp_doing_ajax() ) {
if ( wp_doing_ajax() ) {
wp_send_json_success( $message );
}
}
Expand Down
6 changes: 1 addition & 5 deletions app/FullTemplate/Reset.php
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,7 @@ public function posts( $ids ) {
$post_type = get_post_type( $post_id );
$message = 'Deleted - Post ID ' . $post_id . ' - ' . $post_type . ' - ' . get_the_title( $post_id );

if ( 'elementor_library' === $post_type ) {
$_GET['force_delete_kit'] = true;
}

// do_action( 'templatiq_sites_before_delete_imported_posts', $post_id, $post_type );
do_action( 'templatiq_sites_before_delete_imported_posts', $post_id, $post_type );

wp_delete_post( $post_id, true );

Expand Down
32 changes: 27 additions & 5 deletions app/FullTemplate/inc/importers/wxr-importer/class-wxr-importer.php
Original file line number Diff line number Diff line change
Expand Up @@ -985,7 +985,6 @@ protected function process_post( $data, $meta, $comments, $terms ) {
}

$postdata = apply_filters( 'wp_import_post_data_processed', $postdata, $data );

if ( 'attachment' === $postdata['post_type'] ) {
if ( ! $this->options['fetch_attachments'] ) {
$this->logger->notice(
Expand All @@ -1004,11 +1003,34 @@ protected function process_post( $data, $meta, $comments, $terms ) {
do_action( 'templatiq_wxr_importer.process_skipped.post', $data, $meta ); // phpcs:ignore WordPress.NamingConventions.ValidHookName.UseUnderscores -- 3rd party library.
return false;
}
$remote_url = ! empty( $data['attachment_url'] ) ? $data['attachment_url'] : $data['guid'];
$post_id = $this->process_attachment( $postdata, $meta, $remote_url );

if (
! empty( $postdata['post_title'] )
&& (
strpos( $postdata['post_title'],'.xml') !== false
|| strpos( $postdata['post_title'],'.zip' ) !== false
|| strpos( $postdata['post_title'],'.csv' ) !== false
)
) {
return false;
} else {
$remote_url = ! empty( $data['attachment_url'] ) ? $data['attachment_url'] : $data['guid'];
$post_id = $this->process_attachment( $postdata, $meta, $remote_url );
}
} else {
$post_id = wp_insert_post( $postdata, true );
do_action( 'wp_import_insert_post', $post_id, $original_id, $postdata, $data );
if (
! empty( $postdata['post_title'] )
&& (
strpos( $postdata['post_title'],'.xml') !== false
|| strpos( $postdata['post_title'],'.zip' ) !== false
|| strpos( $postdata['post_title'],'.csv' ) !== false
)
) {
return false;
} else {
$post_id = wp_insert_post( $postdata, true );
do_action( 'wp_import_insert_post', $post_id, $original_id, $postdata, $data );
}
}

if ( is_wp_error( $post_id ) ) {
Expand Down
2 changes: 2 additions & 0 deletions app/Repositories/RemoteRepository.php
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,7 @@ public function get_full_template( int $template_id ) {
'required-plugins' => '',
'license-status' => '',
'templatiq-site-url' => '',
'site_url' => '',
];

$data = $this->get_remote_content( $template_id, 'full-site' );
Expand All @@ -46,6 +47,7 @@ public function get_full_template( int $template_id ) {
$remote_args['license-status'] = $data['license-status'];
$remote_args['templatiq-site-url'] = $data['templatiq-site-url'];
$remote_args['directory-types'] = $data['directory-types'];
$remote_args['site_url'] = $data['site_url'];
}

return wp_parse_args( $remote_args, $defaults );
Expand Down
2 changes: 1 addition & 1 deletion app/Utils/Config.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class Config {

public static function get( string $name ): string {
$config = [
'version' => '0.1.0',
'version' => '0.1.1',
'environment' => 'production',
'could_base' => 'https://templatiq.com/',
];
Expand Down
2 changes: 1 addition & 1 deletion src/js/layout/Header/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -190,7 +190,7 @@ const Header = ( props ) => {
<img src={ Logo } alt="Logo" />
</Link>

<sub>0.1.0</sub>
<sub>0.1.1</sub>

</Suspense>
</div>
Expand Down
4 changes: 2 additions & 2 deletions templatiq.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
* Description: The Ultimate Templates | Craft beautiful website in no time
* Author: wpWax
* Author URI: https://wpwax.com
* Version: 0.1.0
* Version: 0.1.1
* License: GPLv2 or later
* Requires PHP: 7.4
* Text Domain: templatiq
Expand All @@ -29,7 +29,7 @@ public static function instance(): Templatiq {

public function load() {

define( 'TEMPLATIQ_VERSION', '0.1.0' );
define( 'TEMPLATIQ_VERSION', '0.1.1' );

register_activation_hook(
__FILE__, function () {
Expand Down

0 comments on commit 40fdafd

Please sign in to comment.