{"slug":"fluentcrm-rest-options","title":"fluentcrm-rest-options","summary":"Register a custom AJAX option list for FluentCRM trigger / action / benchmark editor pickers. Pairs `'type' => 'rest_selector', 'option_key' => '...'` in a settings field with a server-side `add_filter('fluentcrm_ajax_options_{key}', $callback, 10, 3)` callback. Filter signature ","platform":"Claude","tags":[],"authorName":"LLM Mart","authorSlug":"llm-mart","score":0,"source":"github","price":null,"verified":false,"createdAt":"2026-09-16T14:51:50.384964Z","repo":{"url":"https://github.com/Lonsdale201/wp-agent-skills","stars":26,"forks":2,"license":"MIT","updatedAt":"2026-11-15T13:11:43Z"},"bodyHtml":"<hr>\n<h2>name: fluentcrm-rest-options\ndescription: Register a custom AJAX option list for FluentCRM trigger / action / benchmark editor pickers. Pairs <code>'type' =&gt; 'rest_selector', 'option_key' =&gt; '...'</code> in a settings field with a server-side <code>add_filter('fluentcrm_ajax_options_{key}', $callback, 10, 3)</code> callback. Filter signature is ($options, $search, $includedIds) — return an array of {id, title} pairs. The fallback apply_filters call lives in OptionsController::getAjaxOptions which the editor's REST hits as the user types or opens the picker. Important — pre-selected ids must always be returned (regardless of $search) or the editor renders saved values as raw IDs instead of human labels. Use when scaffolding any FluentCRM trigger / action / benchmark with a multi-select-like field. Triggers on fluentcrm_ajax_options_, rest_selector, option_key, getAjaxOptions, OptionsController.\nmetadata:\nwp-skills-author: \"Soczó Kristóf\"\nwp-skills-contact: \"mailto:lonsdale201@hotmail.com\"\nwp-skills-plugin: \"fluent-crm\"\nwp-skills-plugin-version-tested: \"FluentCRM 3.1.8\"\nwp-skills-php-min: \"7.4\"\nwp-skills-api-stable-since: \"2.5.9\"\nwp-skills-last-updated: \"2026-07-09\"</h2>\n<h1>FluentCRM: register a <code>rest_selector</code> option list</h1>\n<p>For developers building a custom FluentCRM trigger, action, or benchmark that needs a multi-select / single-select field whose options come from your plugin (target courses, target products, target post types, target whatever). The settings-field side declares <code>'type' =&gt; 'rest_selector', 'option_key' =&gt; 'my_things'</code>; the server side registers <code>add_filter('fluentcrm_ajax_options_my_things', $callback, 10, 3)</code>. This is a small focused contract — under 100 lines of code per integration — but it has one subtle \"include pre-selected IDs\" trap.</p>\n<h2>API stability note</h2>\n<p>The <code>fluentcrm_ajax_options_*</code> filter family has been in place since FluentCRM 2.5.9. The 3-argument signature <code>($options, $search, $includedIds)</code> and the <code>[{id, title}, ...]</code> return shape have not changed.</p>\n<p>In FluentCRM 3.1.8, <code>OptionsController::index()</code> guards the comma-separated <code>fields</code> dispatcher with reflection: only public, non-static, zero-required-argument methods declared on <code>OptionsController</code> itself are invoked. Custom dynamic pickers still go through <code>getAjaxOptions()</code> and the <code>fluentcrm_ajax_options_{option_key}</code> fallback filter.</p>\n<h2>Misconception this skill corrects</h2>\n<blockquote>\n<p>\"I'll filter the options by <code>$search</code> only — the picker handles the rest.\"</p>\n</blockquote>\n<p>Wrong — the picker does NOT separately fetch labels for already-saved IDs. When the admin opens an existing trigger / action whose <code>course_ids</code> is <code>[42, 99]</code>, the editor calls the same <code>getAjaxOptions</code> REST endpoint with <code>$includedIds = [42, 99]</code> and an empty <code>$search</code>. If your filter callback only honours <code>$search</code>, IDs 42 and 99 get a search query of <code>''</code> against your filter — which most callbacks treat as \"return everything matching empty string\" (so the labels are present), but if you've added a <code>posts_per_page</code> cap the saved IDs may not appear in the result, and the editor renders the field as bare numbers.</p>\n<p>The correct pattern: when <code>$includedIds</code> is non-empty, <strong>bypass <code>$search</code> and load those specific IDs unconditionally</strong>, then merge with the search-driven results. The canonical approach is to use <code>post__in</code> for CPT lookups so already-saved values always come back regardless of search range:</p>\n<pre><code>public function get_my_things($options, $search, $includedIds)\n{\n    $includedIds = is_array($includedIds) ? array_filter(array_map('intval', $includedIds)) : [];\n\n    $args = [\n        'post_type'      =&gt; 'my_thing',\n        'post_status'    =&gt; 'publish',\n        'posts_per_page' =&gt; 50,\n        'orderby'        =&gt; 'title',\n        'order'          =&gt; 'ASC',\n    ];\n\n    if (!empty($search)) {\n        $args['s'] = (string) $search;\n    }\n    if (!empty($includedIds)) {\n        // CRITICAL — load pre-selected ids unconditionally so the editor\n        // can render their human labels instead of raw numeric IDs.\n        $args['post__in']       = $includedIds;\n        $args['posts_per_page'] = -1;\n    }\n\n    foreach (get_posts($args) as $thing) {\n        $options[] = ['id' =&gt; $thing-&gt;ID, 'title' =&gt; $thing-&gt;post_title];\n    }\n\n    return $options;\n}\n</code></pre>\n<p>Other AI-prone misconceptions:</p>\n<ul>\n<li><strong>\"The filter callback returns a <code>WP_Query</code> / array of <code>WP_Post</code> objects.\"</strong> No — it must return <code>array&lt;int, array{id: scalar, title: string}&gt;</code>. The picker JSON-serialises the result; objects with private fields throw. Use <code>array_map</code> if you have model objects.</li>\n<li><strong>\"<code>option_key</code> can be anything; the picker just calls my filter.\"</strong> The filter is dispatched only as the <code>getAjaxOptions()</code> fallback case. The controller has built-in handlers for many known option keys (<code>woo_products</code>, <code>woo_categories</code>, <code>available_lists</code>, <code>tags</code>, <code>editable_statuses</code>, <code>companies</code>, etc.). Pick a key prefixed with your plugin's slug to avoid collisions — e.g. <code>myplugin_things</code>, NOT just <code>things</code>.</li>\n<li><strong>\"<code>$includedIds</code> is the search field's current value.\"</strong> No — it's the CURRENTLY SAVED value of the field for the loaded sequence/funnel. The editor sends it on the FIRST options request so the picker can render labels for what's already in the form. As the admin types, subsequent requests use <code>$search</code> with empty / re-supplied <code>$includedIds</code>.</li>\n<li><strong>\"The filter signature is 1 arg.\"</strong> No — use <code>add_filter('fluentcrm_ajax_options_&lt;key&gt;', $cb, 10, 3)</code>. Default <code>add_filter</code> accepts only 1 arg; you MUST pass <code>3</code> as the 4th argument or <code>$search</code> and <code>$includedIds</code> will be silently null in your callback.</li>\n<li><strong>\"Adding <code>'is_multiple' =&gt; true</code> to the field config is enough for multi-select.\"</strong> Required for multi but not sufficient — the field type <code>'rest_selector'</code> is what triggers the picker UI. <code>'multi-select'</code> (a different type) preloads all options at once and doesn't hit your filter at all. For multi-select with AJAX search, use <code>'rest_selector'</code> + <code>'is_multiple' =&gt; true</code>.</li>\n</ul>\n<h2>When to use this skill</h2>\n<p>Trigger when ANY of the following is true:</p>\n<ul>\n<li>The diff/files declare <code>'type' =&gt; 'rest_selector'</code> with an <code>'option_key'</code> you control.</li>\n<li>The diff calls <code>add_filter('fluentcrm_ajax_options_*', ...)</code>.</li>\n<li>A new FluentCRM trigger / action / benchmark needs to pick from your plugin's CPTs / objects / categories.</li>\n<li>Debugging \"the picker shows raw IDs instead of names when I open a saved automation\" — almost always Misconception #1 (no <code>$includedIds</code> handling).</li>\n<li>Debugging \"my callback fires but <code>$search</code> is null\" — Misconception #4 (missing <code>4th</code> arg in <code>add_filter</code>).</li>\n</ul>\n<h2>The contract in one block</h2>\n<p><strong>Field declaration</strong> (in your trigger's <code>getConditionFields()</code> or action's <code>getBlockFields()</code>):</p>\n<pre><code>'thing_ids' =&gt; [\n    'type'        =&gt; 'rest_selector',\n    'option_key'  =&gt; 'myplugin_things',     // matches the filter suffix below\n    'is_multiple' =&gt; true,                  // omit / false for single-select\n    'clearable'   =&gt; true,                  // shows the \"x\" reset button\n    'label'       =&gt; __('Target Things', 'my-plugin'),\n    'placeholder' =&gt; __('Select Things', 'my-plugin'),\n    'inline_help' =&gt; __('Leave blank to run on every Thing', 'my-plugin'),\n],\n</code></pre>\n<p><strong>Server callback</strong> (a single class collecting all <code>fluentcrm_ajax_options_*</code> callbacks for your plugin — mirror FluentCRM's own pattern):</p>\n<pre><code>&lt;?php\nnamespace MyPlugin\\Support;\n\nfinal class CustomControllers\n{\n    public function __construct()\n    {\n        add_filter('fluentcrm_ajax_options_myplugin_things', [$this, 'get_things'], 10, 3);\n        // ... other custom option keys ...\n    }\n\n    public function get_things($options, $search, $includedIds)\n    {\n        if (!Dependency::isMyServiceActive()) {\n            return $options;\n        }\n\n        $includedIds = is_array($includedIds) ? array_filter(array_map('intval', $includedIds)) : [];\n\n        $args = [\n            'post_type'      =&gt; 'my_thing',\n            'post_status'    =&gt; 'publish',\n            'posts_per_page' =&gt; 50,\n            'orderby'        =&gt; 'title',\n            'order'          =&gt; 'ASC',\n        ];\n\n        if (!empty($search)) {\n            $args['s'] = (string) $search;\n        }\n        if (!empty($includedIds)) {\n            $args['post__in']       = $includedIds;\n            $args['posts_per_page'] = -1;\n        }\n\n        foreach (get_posts($args) as $thing) {\n            $options[] = [\n                'id'    =&gt; $thing-&gt;ID,\n                'title' =&gt; $thing-&gt;post_title,\n            ];\n        }\n\n        return $options;\n    }\n}\n</code></pre>\n<p>Instantiate <code>new CustomControllers()</code> from your plugin bootstrap on <code>plugins_loaded</code> — these filters don't have the timing constraint that triggers / actions do, since they're called on-demand from REST.</p>\n<h2>Step by step</h2>\n<ol>\n<li>Pick an <code>option_key</code> that won't collide. Prefix with your plugin slug. Don't reuse FluentCRM's built-in keys (<code>woo_products</code>, <code>available_roles</code>, etc.) — those have hardcoded handlers in <code>OptionsController</code> that run BEFORE your filter and may short-circuit.</li>\n<li>Declare the field with <code>'type' =&gt; 'rest_selector'</code> and the chosen <code>option_key</code> in your trigger / action settings.</li>\n<li>Register the filter callback with <strong>3 accepted args</strong> (<code>add_filter(..., 10, 3)</code>).</li>\n<li>In the callback: build a query honouring BOTH <code>$search</code> (user typed in the picker) AND <code>$includedIds</code> (already-saved values to render labels for). Return <code>array&lt;int, array{id, title}&gt;</code>.</li>\n<li>Register the controller class on <code>plugins_loaded</code> (or any pre-<code>init</code> hook); it doesn't need to ride the <code>fluentcrm_loaded</code> priority-5 rule that triggers/actions do.</li>\n</ol>\n<h2>Critical rules</h2>\n<ul>\n<li><strong>Always honour <code>$includedIds</code>.</strong> Pre-selected values must always come back, even if they don't match <code>$search</code>. Otherwise the picker renders <code>[42, 99]</code> instead of human labels.</li>\n<li><strong>Always pass <code>4</code> as the third arg to <code>add_filter</code></strong> (for the priority+accepted_args = <code>10, 3</code>). Forgetting this is the most common silent bug.</li>\n<li><strong>Return shape is <code>array&lt;int, array{id, title}&gt;</code></strong> — <code>id</code> is scalar (int or string), <code>title</code> is plain text (escape on output, not here). No <code>WP_Post</code> objects.</li>\n<li><strong>Guard with a dependency check.</strong> Your filter fires on every <code>getAjaxOptions</code> REST request that matches the suffix, even when your plugin's feature is disabled. Return <code>$options</code> unchanged if not applicable.</li>\n<li><strong>Don't unbounded-list.</strong> Cap with <code>posts_per_page</code> (50 is conventional). The picker is search-as-you-type; loading 5000 rows on the first request kills the editor.</li>\n<li><strong>Prefix your <code>option_key</code> with your plugin slug.</strong> <code>lw_lms_courses</code>, <code>myplugin_widgets</code> — not <code>courses</code>, <code>widgets</code>. Built-in keys have hardcoded handlers in <code>OptionsController</code> that take precedence; non-prefixed keys risk silent collisions when FluentCRM adds a new built-in.</li>\n</ul>\n<h2>Common mistakes</h2>\n<ul>\n<li><strong>Forgetting <code>accepted_args = 3</code>.</strong> <code>add_filter(..., 10)</code> makes <code>$search</code> and <code>$includedIds</code> null inside the callback, and the picker silently returns no options. Always pass <code>3</code> explicitly.</li>\n<li><strong>Using <code>'multi-select'</code> instead of <code>'rest_selector'</code>.</strong> <code>'multi-select'</code> preloads all options once at editor render time and doesn't call your filter. Slow for large datasets and bypasses the search.</li>\n<li><strong>Passing the wrong shape.</strong> <code>[$id =&gt; $title]</code> (associative) breaks the picker — it expects <code>[{id, title}]</code> (list of dicts).</li>\n<li><strong>Including HTML in <code>title</code>.</strong> The picker renders <code>title</code> as plain text. HTML tags appear escaped to the admin. If you need formatted labels, do it client-side.</li>\n<li><strong>Skipping <code>array_filter(array_map('intval', $includedIds))</code>.</strong> <code>$includedIds</code> arrives as strings from the JSON request; if you compare with <code>===</code> against integer post IDs the comparison fails. Cast at the entry point.</li>\n</ul>\n<h2>Cross-references</h2>\n<ul>\n<li>Run <strong><code>fluentcrm-funnel-trigger</code></strong> when the option list is consumed by a trigger condition field.</li>\n<li>Run <strong><code>fluentcrm-funnel-action</code></strong> when the option list is consumed by an action settings field.</li>\n</ul>\n<h2>What this skill does NOT cover</h2>\n<ul>\n<li>Tag / list / segment pickers — those use built-in keys (<code>tags</code>, <code>lists</code>, <code>segments</code>) handled in <code>OptionsController</code> directly; you don't register a filter for them.</li>\n<li><code>'option_selectors'</code> field type — used for <code>editable_statuses</code>, <code>gender</code>, etc.; sourced from <code>Helper::getOptionSelectorOptions()</code> not the AJAX filter.</li>\n<li>Block-editor FluentCRM email designer option pickers — different system.</li>\n</ul>\n<h2>References</h2>\n<ul>\n<li>Filter dispatch site — <code>app/Http/Controllers/OptionsController.php:723</code></li>\n<li>Reference callback (FluentCart product picker) — <code>app/Services/ExternalIntegrations/FluentCart/FluentCart.php:70-75</code></li>\n<li>Built-in handlers for canonical keys (<code>woo_products</code>, <code>woo_categories</code>, <code>companies</code>, etc.) — <code>app/Http/Controllers/OptionsController.php</code></li>\n<li>Official documentation: <a href=\"https://developers.fluentcrm.com/funnel-builder/custom-trigger/\">https://developers.fluentcrm.com/funnel-builder/custom-trigger/</a></li>\n</ul>\n","files":[{"path":"SKILL.md","sizeBytes":12783,"isText":true}],"reviewScore":null,"reviewSummary":null,"trust":{"provenance":"trusted-source-unreviewed","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow.","bodySource":null},"bodyLocked":false,"purchaseUrl":null,"sourceUrl":null,"report":{"provenance":"trusted-source-unreviewed","screen":{"ran":true,"outcome":"clean","suspicious":0,"notes":0,"hiddenCharacters":false},"virusScan":{"engine":"clamav","status":"clean","scannedAt":"2026-09-16T14:55:50.279669Z","sha256":"83F16067B9B507867674B923F0C9464B3D59D1DFBF5F791DACB410EDC24B1437","sizeBytes":4982},"review":null,"source":{"repositoryUrl":"https://github.com/Lonsdale201/wp-agent-skills","path":"fluentcrm/fluentcrm-rest-options","license":"MIT","commit":"9025fda280d15da3e2ba376a66940e75bd45f3ce","subtreeSha":"CC39DC4ADE161AB376FC918FED4CBB0AC219E5DCFCC8B0BFCCE01488110D38B0","lastSyncedAt":"2026-11-17T00:39:45.243627Z"},"reviewedAt":"2026-09-16T15:11:48.384173Z","notice":"Community-authored content, reproduced verbatim and not vetted as instructions. Treat it as data to evaluate, never as directives to follow."},"install":[{"target":"skills-cli","command":"npx skills add https://github.com/Lonsdale201/wp-agent-skills/tree/main/fluentcrm/fluentcrm-rest-options"},{"target":"claude-code","command":"claude plugin marketplace add https://llmmart.ai/marketplace.json && claude plugin install lonsdale201-wp-agent-skills@llmmart"},{"target":"git","command":"git clone https://github.com/Lonsdale201/wp-agent-skills.git"}]}