Code Monkey home page Code Monkey logo

Comments (12)

tn3rb avatar tn3rb commented on August 15, 2024 1

ok here's some of my recommended changes...

i can push these directly to your repo if you like but i had to move everything up a folder

actually... let me just do that because it might be easier for you to copy over changes

from event-espresso-core.

tn3rb avatar tn3rb commented on August 15, 2024

Hi again @Panamus,

What's getting returned for $version_string in can_migrate_from_version() ???
As well, what does version 1.0.2 represent? IS that the current version of your addon? IF so, then that version compare is likely returning false;

what happens if you try:

version_compare($version_string, '1.0.2', '>=')

everything else in this file looks great and I can't see why it would be causing you issues.
sure would be great to be able to see all of the code together.
anyway you can fork your repo to another account and add me as a user there?

from event-espresso-core.

tn3rb avatar tn3rb commented on August 15, 2024

re: help text on questions...

sorry you are having so many troubles with things. The code you have shown me all appears to be fine. That said, instead of adding a model extension for questions to essentially add one field, you could simply use the existing Extra Meta model which is automatically joined to every non-abstract model. So you can add/get/edit/delete meta data for any EE entity object using the following methods:

  • EE_Base_Class::add_extra_meta()
  • EE_Base_Class::get_extra_meta()
  • EE_Base_Class::update_extra_meta()
  • EE_Base_Class::delete_extra_meta()

so in the case of questions, assuming you have a valid EE_Question object you can simply do something like:

        $question->add_extra_meta(
            LD_WPU_META_KEY_HELP_TEXT, // constant so that key doesn't get misspelled 
            'actual help text',
            true // enforce unique entry (no duplicates)
        );

wherever you process your admin logic for the questions.

Then to inject the help text into the frontend registration form, you could use the FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__input_constructor_args filter to modify the form input arguments:

so something like:

add_filter(
    'FHEE__EE_SPCO_Reg_Step_Attendee_Information___generate_question_input__input_constructor_args',
    function(
        array $form_input_args, 
        EE_Registration $registration, 
        EE_Question $question, 
        ?EE_Answer $answer = null
    ): array {
        $help_text = $question->get_extra_meta(
            LD_WPU_META_KEY_HELP_TEXT,
            true
        );
        if ($help_text) {
            $form_input_args['html_help_text'] = $help_text;
            $form_input_args['html_help_class'] = 'css-class'; // default = "description"
            $form_input_args['html_help_style'] = 'inline css';
        }
        return $form_input_args;
    },
    10,
    4
);

from event-espresso-core.

Llanilek avatar Llanilek commented on August 15, 2024

Hi @tn3rb thanks for getting back to me.

What's getting returned for $version_string in can_migrate_from_version()

Absolutely nothing, because it seems can_migrate_from_version isn't being called at all. Tried throwing in EEH_Debug_Tools in there and getting nothing, as well as a few other debugging plugins i've got on the go. nothing picks up the call.

anyway you can fork your repo to another account and add me as a user there?

I'll see what I can do. It wasn't allowing me earlier though.

While we're on the subject, this whole thing is supposed to allow users to add help text to forms. I have no idea how I'd then go about updating the admin question form to allow the capture of that data.

Since I posted this issue I have located a way to hardcode fields to display the help text we need. But it's far from elegant.

<?php

add_action('AHEE__EE_Form_Input_Base___construct_finalize__end', 'input_extra_attributes');

function input_extra_attributes($input)
{
    if (!is_admin()) {
        $label = $input->html_label_text();

        if (strtolower($label) == 'field label') {
            $input->set_html_help_text(esc_html__('help text goes here!', 'event_espresso'));
        }

    }
}

obviously there's already the information there to do this, It was a bit strange that this wasn't already part of the question form in the admin.

EDIT: just seen your reply creep in before I pressed save 😂

That does look like a better place to add this. I had considered using the extra meta as I've done this for adding information to registrations which worked great. This was more an exercise of understanding the DMS doing it this way, should the need for an actual model of our own crop up (and it may well do soon).

from event-espresso-core.

tn3rb avatar tn3rb commented on August 15, 2024

is your DMS script registered during addon registration? ie: when you call EE_Register_Addon::register()

Should have something like:

EE_Register_Addon::register(
    'Promotions',
    [
        'version' => 1.0.2 // <<< current addon version
        'dms_paths' => ['/path/to/your/data_migration_script_folder/'],

from event-espresso-core.

tn3rb avatar tn3rb commented on August 15, 2024

as an alternate way to get me a copy of your codebase, maybe you can zip it all up and use one of these online "send big file" services to email it to me: [email protected]

from event-espresso-core.

Llanilek avatar Llanilek commented on August 15, 2024

Yep

<?php

EE_Register_Addon::register(
    'Ld_WP_Users',
    array(
        'version' => EE_LD_WP_USERS_VERSION,
        'min_core_version' => '4.10.40p',
        'main_file_path' => EE_LD_WP_USERS_PLUGIN_FILE,
        'admin_callback' => 'additional_admin_hooks',
        'module_paths' => array(
            EE_LD_WP_USERS_PATH . 'EED_Ld_WP_Users_SPCO.module.php',
        ),
        'autoloader_paths' => array(
            'EE_Ld_WP_User_Integration' => EE_LD_WP_USERS_PATH . 'EE_Ld_WP_Users.class.php'
        ),
        'model_paths' => array(EE_LD_WP_USERS_CORE . 'db_models'),
        'class_extension_paths' => array(EE_LD_WP_USERS_CORE . 'db_class_extensions' . DS),
        'model_extension_paths' => array(EE_LD_WP_USERS_CORE . 'db_model_extensions' . DS),
        'dms_paths' => array(EE_LD_WP_USERS_CORE . 'data_migration_scripts' . DS),
        'shortcode_paths' => array(EE_LD_WP_USERS_PATH . 'EES_Ld_Txn_Page.shortcode.php'),
    )
);

EE_LD_WP_USERS_VERSION == '1.0.1' for clarity

from event-espresso-core.

tn3rb avatar tn3rb commented on August 15, 2024

🤦🏻 oh dear...

'dms_paths' => array(EE_LD_WP_USERS_CORE . 'data_migration_scripts' . DS),

the folder name was database_migration_scripts

from event-espresso-core.

Llanilek avatar Llanilek commented on August 15, 2024

🤦🏻

I've probably been staring at that for days too... Sorry!!

Well, now that's sorted... I can confirm that it works just fine!

Definitely a can't see the forest for the trees kinda deal!

Now to see if I can hook up the form and get the question populating the help text.

from event-espresso-core.

tn3rb avatar tn3rb commented on August 15, 2024

let me keep poking around and see what other thigns I can fix up for you

from event-espresso-core.

tn3rb avatar tn3rb commented on August 15, 2024

ok created a PR on the repo for you

from event-espresso-core.

Llanilek avatar Llanilek commented on August 15, 2024

Appreciate it thanks @tn3rb!

from event-espresso-core.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.