Category: Process Documentation

Detect tag removed using jQuery

Problem: Want to detect a tag like <div>, when it removed, do something.

Solution: Based on this answer, we can use on’ to detect event like‘remove’:

keep in mind that you must add jQuery (v1.9.1 or above) and jQuery UI -(v1.10.2 or above) scripts in it.

For example, I want to detect a tag with class name “test”:

<div class="test">already to vanish</div>

in the jQuery script part, add below code:

$(".test").on("remove", function () {
    alert("Element was removed, do something");
})

Form submit not working due to hidden required field

Problem: As the title stated, the form submit function not working because of the required field that user forgot to fill, and the field itself is hidden like below code:

<input type="hidden" required name="form_field"  >

so the solution will be adding the value into that hidden value.

Remove duplicate after union two collections in Laravel 5

Problem: Having two collections/MySQL query results and combine them using union():

$result1->union($result2);

then want to remove all duplicate on that union result.

Solution: using unique() to remove duplicates. You can add a parameter like unique(‘id’) to specifically remove which tag name. Example:

$result1 = $result1->unique()->values()->all();

Remember to assign it to a variable or else it will remain the same.

Change localhost to correct domain path in Laravel

Problem: when resetting password or go to other routes, the path should no longer be a localhost but my new domain name. Still, the domain from URL is localhost.

Update .env file to update Laravel domain name

Solution: Update .env file, from APP_URL=http://localhost to APP_URL=https://yourdomain.com

and remember to clean config setting by enter below command:

php artisan config:clear

Remove emoji function in WordPress

Problem: WordPress forced to add emoji function since version 4.2 and want to remove it.

Solution: In the theme folder that you are using, add below code to functions.php:

remove_action( 'wp_head', 'print_emoji_detection_script', 7 );
remove_action( 'admin_print_scripts', 'print_emoji_detection_script' );
remove_action( 'wp_print_styles', 'print_emoji_styles' );
remove_action( 'admin_print_styles', 'print_emoji_styles' );

Auto-renew SSL certificate via letsencrypt in Cent OS 7

Problem: Want to auto-renew SSL cert via letsencrypt. I use letsencrypt-auto --apache -d domain.name to create SSL certificate.

Solution: first make letsencrypt program executable from anywhere since most of you just download a zip file from the Internet.

ln -s /opt/letsencrypt/letsencrypt-auto /usr/bin/letsencrypt 

then you can enter letsencrypt to trigger /opt/letsencrypt/letsencrypt-auto.

above command can eventually renew all certificates that about to expired.

Then add a record to cron job:

enter command crontab -e and add below content

0 0 * * 1 /usr/bin/letsencrypt  renew >> /var/log/le-renew.log

the command will trigger at 00:00 on every Monday. The renew record will save on /var/log/le-renew.log

9/4/2020: below is the create SSL command, just a note for me:

cd /opt/letsencrypt/
./letsencrypt-auto --apache -d www.domain.com

Change WordPress index page content without affect the widget section.

Problem: Want to change WordPress index page content from post to page.

Solution: First go to /var/www/html/passive_income/wp-content/themes/twentyseventeen/index.php, follow below content

<?php
/**
 * The main template file
 *
 * This is the most generic template file in a WordPress theme
 * and one of the two required files for a theme (the other being style.css).
 * It is used to display a page when nothing more specific matches a query.
 * E.g., it puts together the home page when no home.php file exists.
 *
 * @link https://developer.wordpress.org/themes/basics/template-hierarchy/
 *
 * @package WordPress
 * @subpackage Twenty_Seventeen
 * @since 1.0
 * @version 1.0
 */

get_header(); ?>

<div class="wrap">
	<?php if ( is_home() && ! is_front_page() ) : ?>
		<header class="page-header">
			<h1 class="page-title"><?php single_post_title(); ?></h1>
		</header>
	<?php else : ?>
	<header class="page-header">
		<h2 class="page-title"><?php _e( 'Posts', 'twentyseventeen' ); ?></h2>
	</header>
	<?php endif; ?>

	<div id="primary" class="content-area">
		<main id="main" class="site-main" role="main">
   
			<?php
			if ( have_posts() ) :

				/* Start the Loop */
			//	while ( have_posts() ) :
			//		the_post();

					/*
					 * Include the Post-Format-specific template for the content.
					 * If you want to override this in a child theme, then include a file
					 * called content-___.php (where ___ is the Post Format name) and that will be used instead.
					 */
		 //	get_template_part( 'template-parts/post/content', get_post_format() );
	 $id = 1267;
 $post = get_page($id);
 $content = apply_filters('the_content', $post->post_content);
 echo $content;
//https://www.passiveincomehk.com/wp-admin/post.php?post=1267
				//endwhile;

			/*	the_posts_pagination(
					array(
						'prev_text'          => twentyseventeen_get_svg( array( 'icon' => 'arrow-left' ) ) . '<span class="screen-reader-text">' . __( 'Previous page', 'twentyseventeen' ) . '</span>',
						'next_text'          => '<span class="screen-reader-text">' . __( 'Next page', 'twentyseventeen' ) . '</span>' . twentyseventeen_get_svg( array( 'icon' => 'arrow-right' ) ),
						'before_page_number' => '<span class="meta-nav screen-reader-text">' . __( 'Page', 'twentyseventeen' ) . ' </span>',
					)
				);*/

			else :

				get_template_part( 'template-parts/post/content', 'none' );

			endif;
			?>

		</main><!-- #main -->
	</div><!-- #primary -->
	<?php get_sidebar(); ?>
</div><!-- .wrap -->

<?php
get_footer();

keep in mind that the replace $id = 1267; 1267 is the page id.

Fatal error: Uncaught Error: Call to undefined function set_magic_quotes_runtime() in WordPress

Problem: When trying to import RSS via a built-in plugin, there is an error occurred Call to undefined function set_magic_quotes_runtime()

If you are using PHP 5.3 or after, set_magic_quotes_runtime() is already deprecated, although it will not cause a Fatal error it will send an E_DEPRECATED warning.

Solution: Remove all set_magic_quotes_runtime() in the WordPress project

Secured By miniOrange