WordPress plugin cron working only if admin is logged in

The WP Cron .. which runs when user hit website .. Thus if there are no website visits, WP Cron never runs. Now you can use 2 solutions. Disable WP-Cron and use real cron job and then custom real cron job https://support.hostgator.com/articles/specialized-help/technical/wordpress/how-to-replace-wordpress-cron-with-a-real-cron-job use custom interval in wp_schedule_event add_filter( ‘cron_schedules’, ‘myprefix_add_a_cron_schedule’ ); function myprefix_add_a_cron_schedule( $schedules ) … Read more

Replace first occurence of a word with link [closed]

Try this : function guru20_ReplaceWords($text){ $replace = array(‘WordPress Codex’ =&gt; ‘<a href=”http:/codex.wordpress.com”>WordPress Codex [EN]</a>’, ‘WPRecipes’=&gt; ‘<a href=”http://www.wprecipes.com” target=”_blank”>WPRecipes [EN]</a>’, ‘f.php’ =&gt; ‘In die Datei functions.php einfügen.’); $text = str_replace_first(array_keys($replace), $replace, $text); return $text; } add_filter(‘the_content’, ‘guru20_ReplaceWords’); add_filter(‘the_excerpt’, ‘guru20_ReplaceWords’); function str_replace_first($from, $to, $subject) { $from = “https://wordpress.stackexchange.com/”.preg_quote($from, “https://wordpress.stackexchange.com/”).”https://wordpress.stackexchange.com/”; return preg_replace($from, $to, $subject, 1); } You can … Read more

How to resize WordPress images on upload to specific height and width without cropping it

WordPress’s image resizing does not artwork your image onto a canvas, it just resizes mages to fit, cropping if you tell it to. add_image_size(‘contained-image’, 300, 400); will get you the image size you want, but not letterboxed. Images will be resized to fit tightly within a 300×400 rectangle. However they won’t be padded out to … Read more

Best practice for Designing a Plugin with this scenario

You can create a page after your plugin is activated. Take a look at this: register_activation_hook( __FILE__, ‘insert_page’ ); function insert_page(){ $my_page = array( ‘post_title’ => ‘My Page’, ‘post_name’ => ‘MyPage’, ‘post_content’ => ‘My page’s content.’, ‘post_status’ => ‘publish’, ‘post_author’ => get_current_user_id(), ‘post_type’ => ‘page’, ); wp_insert_post( $my_page, ” ); } Then assign your template … Read more

get_plugins() is not give plugin list after performed delete_plugins()

To answer your main question, you are missing one line before calling get_plugins(). Without it, the list of plugins will come from cache. You can use the following sequence: delete_plugins( array( ‘akismet/akismet.php’ ) ); wp_clean_plugins_cache( false ); get_plugins(); WARNING: it is not recommended using delete_plugins() in scripts, unless it is a part of complete procedure … Read more