This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Need WordPress access but only have FTP access? | |
//This snippet will let you create an administrator user, as long as you can get it onto the server in the root of the site | |
//Then visit https://www.site.com/newadmin.php | |
//Finally, DELETE THE SCRIPT when you have gained access. | |
require_once('wp-load.php'); | |
$userdata = array( | |
'user_login' => 'newadmin', | |
'user_email' => '[email protected]', |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Wow I don't miss working on Drupal. Anyway, I needed to do so recently and this took a little Googling to figure out. | |
//Drupal 7 select fields can have optgroups if you make their options an array of arrays, keyed by the optgroup names | |
function mymodule_form_alter(&$form, &$form_state, $form_id){ | |
//assuming we are trying to alter the form of a custom node type called event | |
if ($form_id == 'event_node_form') { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//This is how to set up a cron job via PHP in WordPress. | |
//Do not rely on simply adding it via a plugin like WP Crontrol, as WordPress occasionally loses cron jobs or fails to reschedule them. | |
//1. Add the function you want to run regularly, and an action which will trigger the function. | |
function mytheme_cron_function(){ | |
//Do some things... your custom code goes here. | |
} | |
add_action('mytheme_cron_hook','mytheme_cron_function');//name of action, name of function to run |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Since 5.3 WordPress spits out this notice: add_submenu_page was called incorrectly. The seventh parameter passed to add_submenu_page() should be an integer representing menu position. | |
//I've fixed my own plugins, but it's still coming from a WP Engine mu-plugin which I can't fix or disable, and I still want WP_DEBUG_DISPLAY enabled so I can see other errors and warnings. | |
//Solution: apply_filters( 'doing_it_wrong_trigger_error', true, $function, $message, $version ) | |
function mf_hide_annoying_notice($a, $function) { | |
if($function == 'add_submenu_page') return false; | |
} | |
add_filter('doing_it_wrong_trigger_error','mf_hide_annoying_notice',10,2); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Use nav_menu_item_args hook to add extra HTML to a specific menu item. It will appear inside the <li> | |
//See $item and $args for other things you can inspect and modify | |
function mytheme_nav_menu_item_args($args,$item,$depth){ | |
//print_r($item); | |
//print_r($args) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//see https://gist.github.com/woogists/c15230393ba094d9da33a19a02e20a15 for the general approach to making custom tabs | |
add_filter( 'woocommerce_product_tabs', 'my_new_product_tabs' ); | |
function my_new_product_tabs( $tabs ) { | |
$tabs = array(); //Remove default tabs (optional) | |
global $post; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#Using CPanel to password protect a CodeIgniter subdirectory, and getting a 404 error when trying to access the subdirectory? I got u fam. | |
# This goes in the .htaccess file in the directory you wish to protect | |
#The critical line is ErrorDocument 401 "Authorisation Required" | |
#----------------------------------------------------------------cp:ppd | |
# Section managed by cPanel: Password Protected Directories -cp:ppd | |
# - Do not edit this section of the htaccess file! -cp:ppd | |
#----------------------------------------------------------------cp:ppd | |
AuthType Basic | |
AuthName "My extremely secret directory" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
$('a[href*="#"]:not([href="#"])').click(function() { | |
if (location.pathname.replace(/^\//,'') == this.pathname.replace(/^\//,'') && location.hostname == this.hostname) { | |
var target = $(this.hash); | |
target = target.length ? target : $('[name=' + this.hash.slice(1) +']'); | |
if (target.length) { | |
offset = 100; //px, enough to clear the sticky nav menu | |
$('html,body').animate({ scrollTop: target.offset().top - offset }, 600); | |
return false; | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
// The issue: | |
// You want to use WP Bakery for your WooCommerce shop page. | |
// You can enable WP Bakery for that page, but custom Design Options are not showing. | |
// The explanation: | |
// WP Bakery keeps those custom design changes as a CSS string, stored as post meta on the page you are using for your shop page. | |
// Unfortunately that CSS is not being output by your theme, hence your custom design changes are not working. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?php | |
//Wonky formatting on WooCommerce pages and only on WooCommerce pages? P tags where you don't want P tags? | |
function remove_autop_for_wc(){ | |
remove_filter('woocommerce_short_description','wpautop'); | |
} | |
add_action( 'init', 'remove_autop_for_wc', 999999 ); | |
?> |