Articles of php

Plugin exceeds memory limit

I’m bulk deleting posts from my WordPress site using the function wp_delete_post and categories using wp_delete_category. That are about 100.000 posts and 4.000 categories, and after a while I get a PHP Error PHP Fatal error: Allowed memory size of … bytes exhausted That’s what I do inside my code: // get all IDs from […]

How to generate page content from database the right way?

I am creating many pages and store them into the database. I am first styling them and than storing them. The idea is to use page.php to check the page id and display the needed post. This is all good, but I have many pages in the website. WHich means I have to perform the […]

external wordpress pages using wp-blog-header

I am setting up a few sections of a website external to the core wordpress installation, but I still want to use the built in wpdb functions, and/or header files from wordpress. I follow the instructions outlined in wordpress, setting up my headers: <? require(‘../cms/wp-blog-header.php’); define(‘WP_USE_THEMES’, false); . . ?> Everything works great. I can […]

how to get permalink structure with php

I need to make if statements for every permalink structure, so I need to know if there is a function that returns to me the actual selected permalink structure by the user. To make it simple all I need to know is if this permalink: www.site.com/?p=22; a condition will apply else if this structure www.site.com/cat/title […]

Extend a class of a plugin

There is a plugin that uses a class; and create an object like this: class WC_Disability_VAT_Exemption { public function __construct() { add_action( ‘woocommerce_after_order_notes’, array( $this, ‘exemption_field’ ) ); } public function exemption_field() { //some code here } } /** * Return instance of WC_Disability_VAT_Exemption. * * @since 1.3.3 * * @return WC_Disability_VAT_Exemption */ function wc_dve() […]

Calculations in functions.php

I’ve created an invoice theme for myself and I’m trying to get the invoice total in a custom column. I’ve tried adapting the code I’m using within the template page to display this in the functions.php file but it’s not working. I’m getting an operand error where my multiplication operand is and I don’t know […]

Customizer Show/Hide

In my Customizer, I have a checkbox to “Display Title”. I want the title to display by default (which it is in the Customizer) but the Customizer settings need to be saved in order for it to display on the live site. I would like it to display without having to save the settings first. […]

How can I generate random numbers inside my shortcodes on each implementation?

I am making shortcodes with the random class like this The random alphnumeric generator: function getRandomCode(){ $alphanumeric = “0123456789abcdefghijklmnopqrstuvwxyz”; $su = strlen($alphanumeric) – 1; // echo ‘<br/>’; // // echo rand(0, $su); // // echo ‘<br/>’; // // echo substr($alphanumeric, rand(0, $su), 3); // // echo ‘<br/>’; echo substr($alphanumeric, rand(0, $su), 3) . substr($alphanumeric, rand(0, […]

PHP Deprecated: WP_RSSjb has a deprecated constructor

I get messages in the debug.log for PHP Deprecated: Methods with the same name as their class will not be constructors in a future version of PHP; WP_RSSjb has a deprecated constructor in /home/dccomp/competitions.com/wp-content/plugins/rss-just-better/RSS-just-better.php on line 57. How can I modify this? The line is class WP_RSSjb extends WP_Widget { /** * Widget setup. */ […]

Determining where fopen() is writing files when used from WordPress AJAX call

I have a WordPress Plugin which uses AJAX to send mail. It works fine. Now I want to put a bit of code to write a log file when the mail is sent. The parameter $u is simply a bit of text to be logged. function writeToLog( $u ) { $path = ‘log.txt’; $agent = […]