Replace existing pages with new pages, keep menu links

I was shocked to see that such a simple thing is not readily supported. I was even more shocked to see that no one had a good answer here on StackExchange! Happily, I found this post: https://wordpress.org/support/topic/updating-current-page-with-new-built-page/ …and am grateful for the answer provided by Joy (@joyously on WordPress.org and Slack) “If you need to … Read more

WooCommerce – Where is functions.php?

Woocommerce is a plugin. The functions.php file is a Theme component, which is auto-loaded by WordPress Core when the theme boots. While Woocommerce, or any other plugin, may have a file named functions.php but such is not required and it is not the functions.php typically referenced here and elsewhere when people suggest adding code that … Read more

Override core woocommerce class

1) There is a hook for the first one: You can use the apply_filters Their code: apply_filters( ‘woocommerce_get_discounted_price’, $price, $values, $this ); Your code: add_filter( ‘woocommerce_get_discounted_price’, function($price, $values, $this) { //return whatever you want },10,3 ); //*PHP 5.3 and up you can pass whatever function you want into the second parameter of the add_filter function. … Read more

Using spl_autoloading within WordPress plugin

I think the problem here is that you’re using a relative path in autoload.php inside the src/ subfolder, Try for example to modify your src/autoload.php to use absolute paths instead: \spl_autoload_register( function( $class ) { $dir = plugin_dir_path( __FILE__ ); $file = str_replace( ‘\\’, “https://wordpress.stackexchange.com/”, $class ) . ‘.php’; $path = $dir . $file; if( … Read more

Upload files programmatically to users

it was just missing $upload_dir[‘path’] . “https://wordpress.stackexchange.com/” . $upload_file_name in $uploaded_file[‘attach_id’] = wp_insert_attachment($attachment, $upload_dir[‘path’] . “https://wordpress.stackexchange.com/” . $upload_file_name); require_once(ABSPATH . ‘wp-admin/includes/image.php’); //Generate the metadata for the attachment, and update the database record. $attach_data = wp_generate_attachment_metadata($uploaded_file[‘attach_id’], $upload_dir[‘path’] . “https://wordpress.stackexchange.com/” . $upload_file_name);

wp_enqueue_scripts not working inside shortcode

$shortcode = new Shortcode_Class(); class Shortcode_Class { /** * If you should add the script or not * * @var bool */ private $addScript = false; public function __construct() { add_shortcode(‘test_shortcode’, array($this, ‘shortcode_content’)); // wp_enqueue_scripts // If you use the below the CSS and JS file will be added on everypage // add_action( ‘wp_enqueue_scripts’, array($this, … Read more

Creating search filter through plugin

You can add more than one filter call, so each of your custom meta_key‘s can be handled in separate code and when executed will cumulatively adjust the query. Perhaps look at the pre_get_posts filter rather than parse_query (although the solution I’m suggesting could possibly work in either case). pre_get_posts gives you access to the current … Read more