Run a Parallel PHP Application with WordPress

You can use the WP REST API plugin to add/manipulate/present media of a WordPress install from within your app. The page creation part I am not sure of, perhaps it’ll need to be done manually – or you can create pages via the /pages/ endpoint. I’ll let someone correct me if I’m wrong, but the … Read more

Why is it necessary to prevent direct access to included files?

Because you could have code that alters the database, shows sensitive information or otherwise trigger events you only want it to execute under the conditions you design without error. Many core files only hold functions which don’t execute if the file is accessed directly. When they do alter data/files they usually check for $_POST actions, … Read more

Wrap each shortcode in array to div

You need to recurse into the shortcode content ($m[5] as returned by get_shortcode_regex()), the standard way being to use preg_replace_callback(): public function wrapShortcode( $content ) { $content = preg_replace_callback( “https://wordpress.stackexchange.com/” . get_shortcode_regex() . ‘/s’, array( $this, ‘wrapShortcodeCallback’ ), $content ); remove_filter( ‘the_content’, array( $this, ‘wrapShortcode’ ), -9999999 ); // Stray spaces can create lost paragraph … Read more

Modify Maximum upload file size text

This text is coming from wp-admin/includes/media.php#L1946 There is not filter is available to modify the text. But still if you wish you can use gettext filter to modify the text. add_action(‘post-html-upload-ui’, function () { add_filter(‘gettext’, ‘media_upload_limit_custom_text’); }); /** * Customize the max media size text * @param string $text * @return string $text */ function … Read more

How do I output a database option that is an array into a get_posts array?

You could use wp_parse_id_list() to sanitize your comma seperated list of post IDs. It’s defined as: function wp_parse_id_list( $list ) { if ( !is_array($list) ) $list = preg_split(‘/[\s,]+/’, $list); return array_unique(array_map(‘absint’, $list)); } where we can see that it returns unique array values as well. Note that absint() is defined in core as abs( intval() … Read more

Upgraded to php7.0, now ssh updates don’t work [closed]

I was having a similar problem with getting ssh to work after the php 7.0 upgrade. I went through the steps of this tutorial and got it working. I also had to chmod 775 the wp-content directory. However, the wp-content/plugins direcotry at chmod 755 works.

Enhanced WordPress Search

It is somehow possible as you can phrase SQL queries to match your conditions but it will not perform very well as the MySQL table structure is not designed for this kind of full-text search. However, the solution requires more than just passing the search query (the user input) to the default WordPress s query … Read more

Count number of published posts by type

If you prefer the $wpdb direct queries you can use something like this: global $wpdb; $count = $wpdb->get_var( “SELECT COUNT(ID) FROM {$wpdb->posts} WHERE post_type=”code” and post_status=”publish”” ); echo $count; In the sql query above change the post_type to whatever you like. This will return count of published posts under specific post type only. If you … Read more