Articles of php

dbDelta support for FOREIGN KEY

On PHP 5.3.13/MySQL 5.5.21 the following code doesn’t work: if($check_custom_fields_form!=1){ $sql = “CREATE TABLE IF NOT EXISTS “. $table_custom_fields_form .” ( `form_name` longtext NOT NULL, `field_id` bigint(20) NOT NULL, FOREIGN KEY (`field_id`) REFERENCES $table_custom_fields (`ID`) ON DELETE CASCADE ON UPDATE CASCADE ) CHARACTER SET utf8 COLLATE utf8_general_ci”; dbDelta($sql); } if($check_subscribe_cat!=1){ $sql = “CREATE TABLE IF […]

WordPress and event-driven programming – what is it about?

I want to state very clearly that this does not intend to revive the discussion about functional/procedural programming versus object-oriented programming. There is plenty said about that, on WPSE and all over the net. But a while ago I’m reading over some of the discussions about the programming foundations of WordPress and I read something […]

Setting custom cookies in WordPress

I am trying to set cookies to re-route returning users to my a specific page within my WordPress site. I’d like some advice with these 2 things: Where in the WordPress php files should cookies be checked before loading any content to handle a redirect? Is there a good file this should exist in over […]

Reposition WooCommerce breadcrumb outside of wrapper content

I currently have this code in my functions file for the WooCommerce plugin.. function my_theme_wrapper_start() { echo the_breadcrumb(); echo ‘<section role=”main”><div class=”wrap”>’; } function my_theme_wrapper_end() { echo ‘</div></section>’; } function mytheme_prepare_woocommerce_wrappers() { remove_action( ‘woocommerce_before_main_content’, ‘woocommerce_output_content_wrapper’, 10 ); remove_action( ‘woocommerce_after_main_content’, ‘woocommerce_output_content_wrapper_end’, 10); add_action( ‘woocommerce_before_main_content’, ‘my_theme_wrapper_start’, 10 ); add_action( ‘woocommerce_after_main_content’, ‘my_theme_wrapper_end’, 10 ); } add_action( ‘wp_head’, ‘mytheme_prepare_woocommerce_wrappers’ […]

What is the best php version to use with WordPress?

What is the best php version to use with WordPress… without going over the top.

PHP unit testing WordPress?

Given how WordPress is written and how it interacts with a database and given how its not very much OOP oriented, is there a way to unit test a theme? is there a way unit test a framework (not a theme framework) that interacts with WordPress, that is, for example, can you write a unit […]

Uploading media with the REST API

I am having trouble when uploading media to a WordPress site with the JSON REST API. With the following code I can upload the photos, but no info is assigned to them, not even the name – in fact the name automatically becomes the URL and filename (without the extension). $username = “ZX”; $password = […]

Any guides on creating custom admin pages?

I basically want to create a table (preferably AJAXified) that lets the user enter a line of information, and be able to add new lines of information, and delete selected ones. I’ve found this post and this post. The design side looks very straightforward, but I want to know about the functionality. How do I […]

Remove “Insert from URL” link in Media upload – WP 3.5

How do I remove the Insert from URL link in the new WordPress 3.5 Add Media popup page? In earlier versions of WordPress, this worked fine: // removes URL tab in image upload for post function remove_media_library_tab($tabs) { if (isset($_REQUEST[‘post_id’])) { $post_type = get_post_type($_REQUEST[‘post_id’]); if (‘premium’ == $post_type) unset($tabs[‘library’]); unset($tabs[‘type_url’]); } return $tabs; } add_filter(‘media_upload_tabs’, […]

Make Google index the entire post if it is separated into several pages

While this is a question, it is as well a serious warning to publishers that separate their posts using <!–nextpage–>. Bare with me. I run a highly trafficked multiple author platform that rank very high on search engines. While making SEO related improvements, I noticed that only the first page of an article that is […]