• Resolved Imageyoancutillas

    (@yoancutillas)


    Hello,

    Thank you for your plugin.

    I noticed that PHP custom codes are not loaded during AJAX requests even when the custom code is set to load “Everywhere”.

    I am a developer so I can help you fixing this issue. The problem comes from this file: lib/release-codes.php lines 263: https://plugins.trac.wordpress.org/browser/custom-codes/trunk/lib/release-codes.php#L263

    if ( file_exists( $file_directory ) && 'default' === $editor_location && !defined( 'DOING_AJAX' ) ) {

    Can you please change this line to the following?

    if ( file_exists( $file_directory ) && 'default' === $editor_location && ( ! defined( 'DOING_AJAX' ) || 'everywhere' === $location ) ) {

    This will allow PHP custom codes to be loaded during AJAX requests as well if it is set as “Everywhere”.

    Thank you 🙂

Viewing 4 replies - 1 through 4 (of 4 total)
  • Plugin Author ImageBilal TAS

    (@bilaltas)

    Hi Yuan, thanks for your feedback and contribution 🙏

    Yes, you’re right. It’s now not able to add custom codes for AJAX requests. But the current condition is to prevent breaking the CodeKit editor saving when someone writes some PHP with error(s).

    Not to miss both benefits, looks like we need to identify “CODEKIT_DOING_AJAX” definition to use directly in the existing condition. We’ll only change “DOING_AJAX” as “CODEKIT_DOING_AJAX” there. Does that sound good to you?

    Otherwise, if someone misses a semicolon in the editor, it will no longer save and site becomes down until someone fixes the file manually. 🙂

    Thread Starter Imageyoancutillas

    (@yoancutillas)

    Hi Bilal,

    Yes, well spotted! I think that would solve both problems, thank you.

    ___

    This is not related, but I also noticed that the $editor_name variable should be passed in the use statement of the function a little below, because it is used but not declared in this function, for example you can replace

    add_action( 'wp', function () use(
    $file_directory,
    $wp_filesystem,
    $code_post_id,
    $location
    ) {

    with

    add_action( 'wp', function () use(
    $file_directory,
    $editor_name,
    $code_post_id,
    $location
    ) {

    (indeed, $wp_filesystem is actually not used in this function so you can replace it)

    Plugin Author ImageBilal TAS

    (@bilaltas)

    Hey @yoancutillas, thanks a lot for your contributions. The both recommendations have been deployed with 2.3.92 version.

    https://wordpress.org/plugins/custom-codes/#developers

    Thread Starter Imageyoancutillas

    (@yoancutillas)

    Thank you 🙂

Viewing 4 replies - 1 through 4 (of 4 total)

You must be logged in to reply to this topic.