Is it worth checking if class_exists when developing a plugin and how to do it?

Use an auto-loader and let PHP resolve that problem for you. Then only one class will be loaded, and you don’t have to worry about doubled declarations. Example I have an (unfinished) plugin Post Notes with the following file structure: – plugin.php – php/ – Nonce_Validator.php – Save_Post_Request_Validator.php – Textarea.php – … and more This … Read more

register_uninstall_hook() vs uninstall.php – which one is better way to handle plugin uninstallation script?

The benefit of uninstall.php, and the reason that it was introduced, is that it allows you to isolate your uninstallation code from the rest of your plugin’s code. This means that your entire plugin doesn’t have to be loaded when it is uninstalled. That minimizes the chance that your plugin will inadvertently run code during … Read more

How to properly validate data from $_GET or $_REQUEST using WordPress functions?

WordPress doesn’t provide any specific data validation functions for SUPERGLOBALS. I use the PHP filter_input function then escape it as I would any untrusted variable. $url = filter_input( INPUT_GET, ‘some_query_string’, FILTER_VALIDATE_URL ); echo ‘<a href=”‘. esc_url( $url ). ‘”>Click Me</a>’; The PHP filter input accepts: Validate filters Sanitize filters Other filters Additional Filter flags

How to add tab which is visible only in admin side of product in woocommerce? [closed]

I have worked on your issue and found a solution after some Google. Note: Add the below mentioned code to theme’s functions.php or any plugin’s file. Code: This filter function will add a custom tab to the Products Data metabox <?php add_filter( ‘woocommerce_product_data_tabs’, ‘add_my_custom_product_data_tab’ , 99 , 1 ); function add_my_custom_product_data_tab( $product_data_tabs ) { $product_data_tabs[‘my-custom-tab’] … Read more

When would I use either function for plugins?

Return values of the three mentioned functions 1. plugin_dir_path( __FILE__ ) returns the servers filesystem directory path pointing to the current file, i.e. something along the lines of /home/www/your_site/wp-content/plugins/your-plugin/includes/ This can be used for loading PHP files. 2. plugins_url() returns the web address of the current WordPress installation’s plugin folder, i.e. something along the lines … Read more

How to use PanelColorSettings in custom Gutenberg block?

First you need to import the component – const { PanelColorSettings, } = wp.editor; then inside the InspectorControls you call the component <PanelColorSettings title={ __( ‘Color Settings’ ) } colorSettings={ [ { value: color, onChange: ( colorValue ) => setAttributes( { color: colorValue } ), label: __( ‘Background Color’ ), }, { value: textColor, onChange: … Read more

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)