{"id":22606615,"url":"https://github.com/benjaminmedia/wp-cxense","last_synced_at":"2025-04-11T05:15:27.057Z","repository":{"id":37546227,"uuid":"69002187","full_name":"BenjaminMedia/wp-cxense","owner":"BenjaminMedia","description":"A generic WordPress plugin for integrating with cXense","archived":false,"fork":false,"pushed_at":"2024-02-12T09:52:12.000Z","size":469,"stargazers_count":2,"open_issues_count":2,"forks_count":1,"subscribers_count":13,"default_branch":"master","last_synced_at":"2025-04-11T05:15:16.972Z","etag":null,"topics":["cxense","wordpress","wordpress-plugin","wp-cxense"],"latest_commit_sha":null,"homepage":"","language":"PHP","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/BenjaminMedia.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.md","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-09-23T07:48:07.000Z","updated_at":"2021-10-01T13:00:49.000Z","dependencies_parsed_at":"2024-02-12T10:50:02.584Z","dependency_job_id":"dd9d0023-0bc2-4a7c-ae7b-65924a6761f1","html_url":"https://github.com/BenjaminMedia/wp-cxense","commit_stats":{"total_commits":218,"total_committers":20,"mean_commits":10.9,"dds":0.8256880733944953,"last_synced_commit":"33efcc5a8f6c4182c327bf458aa1d9fd16824726"},"previous_names":[],"tags_count":96,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenjaminMedia%2Fwp-cxense","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenjaminMedia%2Fwp-cxense/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenjaminMedia%2Fwp-cxense/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/BenjaminMedia%2Fwp-cxense/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/BenjaminMedia","download_url":"https://codeload.github.com/BenjaminMedia/wp-cxense/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248345268,"owners_count":21088245,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["cxense","wordpress","wordpress-plugin","wp-cxense"],"created_at":"2024-12-08T14:14:20.045Z","updated_at":"2025-04-11T05:15:27.034Z","avatar_url":"https://github.com/BenjaminMedia.png","language":"PHP","funding_links":[],"categories":[],"sub_categories":[],"readme":"# Bonnier Publications - WordPress cXense plugin\nThis plugin enables your WordPress site to integrate with cXense.\nIt adds the meta tags and scripts needed by cXense in order to scan your site.\nIt also calls cXense whenever you make changes to your content.\nFinally it adds the possibility to save a cXense recommendation widget per content type and provides hooks to call them in your view/theme.\n\n### Requirements\n- WordPress 4.3 or higher\n- Language support (Optional) Polylang plugin must installed and activated version 1.8.4 or higher\n- PHP 7.1 or higher\n\n### Installation/Configuration\n\nInstall through composer:\n\n``` bash\ncomposer require benjaminmedia/wp-cxense\n```\n\nDownload lastest release from: https://github.com/BenjaminMedia/wp-cxense/releases\nAnd unzip and place in your /wp-content/plugins directory.\n\n#### Settings\nOnce you have installed and activated the plugin then make sure that you have\na set of api credentials for the cXense API.\nOnce you have your credentials you may go to the settings page labeled cXense.\nHere you must enter your ```cXense Site ID```, ```cXense API user```,\n ```cXense API key``` and finally your ```cXense Organisation prefix```.\n\n##### Remember the plugin will not work until you check the ```Enable``` switch in the settings page\n---\n\n### Widgets\nThe plugin will generate a ```CX Widget ID``` settings field for each post type\nyou have available on your WordPress Installation. Here you must enter the\ncXense recommendation widget ID that you would like represented on your\ncontent type.\n\nFor debug purpose you can enable or disable the query cache. It is recommended to be enabled in production.\n\nSortBy Widget ID will be only used for widgets sortby options in wp-base.\n\n#### Rendering widgets\n\nIn order to render the widgets available for your post you should make sure\nthat you have filled out the ```CX widget ID``` field in the plugin settings\npage.\n\nWhen rendering the widgets the plugin provides you with two options:\n\n1. Let cXense render the HTML of the widgets\n2. Get the data and for the widget and build the HMTL yourself\n\nOnce you have picked the method you want to use you should go to the theme file\nthat represents the single view of your post_type from this file you may call the\nfollowing methods to get the widget data:\n\n###### Let cXense render the HTML of the widgets\n\n``` php\n\nWpCxense::instance()-\u003erender_widget();\n\n```\n\nThe sample output of this function could look like:\n\n``` html\n\n\u003cdiv id=\"targetElement\"\u003e\n        \u003cscript type=\"text/javascript\"\u003e\n            document.write(data.response.template + '\\n');\n        \u003c/script\u003e\n\n    \u003cdiv class=\"item\"\u003e\n        \u003ca id=\"cXLinkIditl9abmrwgnm6p94\" href=\"http://api.cxense.com/public/widget/click/GHVxM-yuEld7tlHB8lLrWC5jLoQYrF5gUs1rQK6CLuzqTVYiNXv6oZIhhNasqiBbPYlY2_nBmMn2aM8imnN5Y0VXxers9cYtaPN1-kIKDNd-dw78wcSKMCLNK45PnASBJagtCbsrhK9JwUfBEeuVtGs1L3HeqDWe5qKvKc7dWeFC77wB_w5fBFQlcXCgyOLmfQwO21Cfh2QcoBs4J8A2pN6OkKQOPyC0lwIbM30ZaHAUZ774R5ASnLc6GLOpPyN38YwdvjAL7iAigpE4fpAcq6O5HXG6PbQljmp-wk1GJvw6hWAigKp1gsSJmhPhZjhIP-pbABDfOl7OkS-k42wjAxKuCeukqgJW04_J0tWRGygNzTm4Tno54OQAgHVWnh4iZDyOaXBjkKAGQHDMPY7IGBfSjDZKOiviklKINjAbb1STXbgDr27BhMZKuWC-y4fMWVnganRI7IVRA8bgd6zl0V4DX9VjvTUEJLSOWq-T6kEzsdG-ENGrw4EVauuyd1h9kysOAuH_egm1XoDcmHpYSMzPmhmyeOgfJpGFg6L09vXFTi6GQ39q4kJYMeQSlC_xO3f1vJzIhn9Y9D6kRIVQMASyFC31lcSwR9pVoOcQav5duA-d4wVciKTKq_RehjVfwqEFxYz9v0WTo8Sqcoc0\" target=\"_top\"\u003e\n            \u003cdiv class=\"thumbnail\" style=\"width: 300px; height: 200px;  overflow: hidden; position: relative;\"\u003e\u003cimg style=\"position: relative;   left: 0px;   top: -7.2px;\" src=\"http://content-thumbnail.cxpublic.com/content/dominantthumbnail/f95381682e3604de99d30788b24fb3a1538616ee.jpg?57e79849\" width=\"300\" height=\"236\" alt=\"\"\u003e\u003c/div\u003e\n\n            \u003cdiv class=\"text-wrapper\"\u003e\n                \u003ch3 class=\"title\"\u003eHindbærsmoothie med æble og lakrids\u003c/h3\u003e\n\n            \u003c/div\u003e\n        \u003c/a\u003e\n    \u003c/div\u003e\n\n\n\n    \u003cdiv class=\"item\"\u003e\n        \u003ca id=\"cXLinkIditl9abmrpj1kla6v\" href=\"http://maaltid.nu/herkules-pavillonens-bedste-frokost-opskrifter\" target=\"_top\"\u003e\n            \u003cdiv class=\"thumbnail\" style=\"width: 300px; height: 200px;  overflow: hidden; position: relative;\"\u003e\u003cimg style=\"position: relative;   left: 0px;   top: -7.2px;\" src=\"http://content-thumbnail.cxpublic.com/content/dominantthumbnail/cf4b03ff330434ddec3447a014ccbd4a15089290.jpg?57d6c1e2\" width=\"300\" height=\"236\" alt=\"\"\u003e\u003c/div\u003e\n\n            \u003cdiv class=\"text-wrapper\"\u003e\n                \u003ch3 class=\"title\"\u003eHerkules Pavillonens bedste frokost-opskrifter\u003c/h3\u003e\n\n            \u003c/div\u003e\n        \u003c/a\u003e\n    \u003c/div\u003e\n\n\t...\n\n\u003c/div\u003e\n\n```\n---\n\n###### Get the data and for the widget and build the HMTL yourself\n\n``` php\n\nWpCxense::instance()-\u003eget_widget_data();\n\n```\n\nThe sample output of this function could look like:\n\n\n``` php\n\narray (size=12)\n  0 =\u003e\n    object(stdClass)[2636]\n      public 'recs-articleid' =\u003e string '795' (length=3)\n      public 'bod-pagetype' =\u003e string 'recipe' (length=6)\n      public 'dominantthumbnail' =\u003e string 'http://content-thumbnail.cxpublic.com/content/dominantthumbnail/f95381682e3604de99d30788b24fb3a1538616ee.jpg?57e79849' (length=117)\n      public 'dominantthumbnaildimensions' =\u003e string '300x236' (length=7)\n      public 'title' =\u003e string 'Hindbærsmoothie med æble og lakrids' (length=37)\n      public 'click_url' =\u003e string 'http://api.cxense.com/public/widget/click/HV4bL7qxuVIVUmrMEsh4zQ6S2A5_BkkxEuByIzyDKMZAYCrJlJOTpy7QFvYxf7dkW0ljBE_55ig9vYxG3FNaXmKGsr03HH5w1wa7-E6mbJI-gdqHJNx6pgIjvKyM8TUGnhfwe0NsyjAkgzirNM66WfPhG9_Z9lsiWIJauO3C82KWYdRhA99EBXg6Ynsh9xwIq62wNJAaj_OPTVFhUuGiLxW7uVQ4DNT0BjRcn8ne0Uq6y8Ew0DYUDCfCFp6DwOy_D9MK7j5wpKSfRykLOGNNo35udNcfALBcZJfoMZ7Uqgs19IZeGrAv11RDIz1cNBmWq3yEn-QKqeKFgK7cqwjKeCr91PERbwGbDu4kN9xkv1NPjTK1M_attpQjlCLy3E9_JstO-aCxP6XtmtnIExUnl1Qq7iVPXAbP3fxlT3wmIOetk4IvoGKsXhdFkRIMCD1owQwY27bVvzwuPCgTXJ-7UO'... (length=599)\n      public 'url' =\u003e string 'http://maaltid.nu/opskrifter/hindbaersmoothie-med-aeble-og-lakrids' (length=66)\n  1 =\u003e\n    object(stdClass)[2672]\n      public 'recs-articleid' =\u003e string '1369' (length=4)\n      public 'bod-pagetype' =\u003e string 'recipe' (length=6)\n      public 'dominantthumbnail' =\u003e string 'http://content-thumbnail.cxpublic.com/content/dominantthumbnail/6b0ddce458039f3905b5b3515356002536ab614c.jpg?57ea261a' (length=117)\n      public 'dominantthumbnaildimensions' =\u003e string '300x236' (length=7)\n      public 'title' =\u003e string 'Italiensk til middag: Risotto med 2 slags græskar og salvie' (length=60)\n      public 'click_url' =\u003e string 'http://api.cxense.com/public/widget/click/mLsD8MoXunkEcOtky6wQJXpRjzYcvvrFoXsONQdOI5FDqsmnlun6sVcaK-PIsvyT9KoXSvOKxiS4wzBrjGb0PaCtk_1bFn88sHSzq7LJF4CL7-Q4-50nJl3JC3oyrnAM1W_Cub7qXcAHSFmBjVkBjAGRaiA_F-Du9Y1q2by9YikilWco43hRZeUHVyQ2RLOZ7as8C1SeEXdKHeDi8HT5SGqMox-hAdBhwHNLtXLdJ_t1u9G90QOmQw-xitTc4PUknHSdtPyiDgYrBNNxHhOehs0_wHKGxka4k-g6VOAo7ovFGF2aRB-32QAqSPu_ohd-nNO_J0tEMll1uofTI9XCePnkI2O1W0Cq6MkEcyWVZQ-72hWiTrfn2z8x-BRd9ZE8cFvdWV8OU-Ojf02KEKesGfVgUltFY-HLImdE2NCkGV-jk7RoHYXesghIvfTufvKnMORmayI5lkLDZQ5Dp7u9wh'... (length=613)\n      public 'url' =\u003e string 'http://maaltid.nu/opskrifter/kom-i-godt-humor-med-graeskarrisotto-med-salvie' (length=76)\n  2 =\u003e ...\n\n```\n\n### Documents\n\n#### Searching documents\n\nIf the key 'query' is missing from the search array then a [DocumentSearchMissingSearch](https://github.com/BenjaminMedia/wp-cxense/blob/search_documents/src/Bonnier/WP/Cxense/Exceptions/DocumentSearchMissingSearch.php) exception is thrown.\n\n##### Search\n\n``` php\nWpCxense::instance()-\u003esearch_documents([\n    'query' =\u003e 'search_term', // mandatory\n    'page' =\u003e 1, // optional, defaults to 1\n    'count' =\u003e 10, // optional, defaults to 10\n    'filter_operator =\u003e 'AND', // optional, defaults to OR\n    'filter' =\u003e [ // optional\n        'field' =\u003e [\n            'value',\n        ],\n    ],\n    'filter_exclude' =\u003e [ // optional\n        'field' =\u003e [\n             'value',\n        ],\n    ],\n    'facets' =\u003e [ // optional\n        0 =\u003e [\n            'type' =\u003e 'string',\n            'field' =\u003e 'field'\n        ],\n        1 =\u003e [\n            'type' =\u003e 'string',\n            'field' =\u003e 'field'\n        ]\n    ],\n    'spellcheck' =\u003e true, // optional\n    'highlights' =\u003e [ // optional\n        0 =\u003e [\n            'field' =\u003e 'body',\n            'start' =\u003e '\u003cem\u003e',\n            'stop' =\u003e '\u003c/em\u003e',\n            'length' =\u003e 50\n        ]\n    ]\n]);\n```\n\nSearching documents will return an object of the following format:\n\n``` php\nobject(stdClass)[543]\n  public 'facets' =\u003e\n    array (size=2)\n      0 =\u003e\n        object(stdClass)[538]\n          public 'buckets' =\u003e\n            array (size=6)\n              ...\n      1 =\u003e\n        object(stdClass)[542]\n          public 'buckets' =\u003e\n            array (size=3)\n              ...\n  public 'totalCount' =\u003e int 79\n  public 'matches' =\u003e\n    array (size=10)\n      0 =\u003e\n        object(Bonnier\\WP\\Cxense\\Parsers\\Document)[521]\n          public 'id' =\u003e string '551790ba522b4b9427ca947e1b3353e137d78a85' (length=40)\n          public 'siteId' =\u003e string '1129402680464567580' (length=19)\n          public 'score' =\u003e float 2.0455377\n          public 'fields' =\u003e\n            array (size=10)\n              ...\n          public 'highlights' =\u003e\n            array (size=1)\n              ...\n  public 'spellcheck' =\u003e\n      array (size=1)\n        0 =\u003e\n          object(stdClass)[663]\n            public 'term' =\u003e string 'mor' (length=3)\n            public 'suggestions' =\u003e\n              array (size=0)\n                ...\n```\n\nThe 'matches' key contains an array of objects that have the 'fields' value accessible directly through the magic method __get(). This means that you can call any field from the 'fields' with the direct pointer:\n\n``` php\n$objResults-\u003ematches[0]-\u003eauthor;\n```\n\nA complete document result looks like:\n``` php\nobject(Bonnier\\WP\\Cxense\\Parsers\\Document)[710]\n  public 'id' =\u003e string '551790ba522b4b9427ca947e1b3353e137d78a85' (length=40)\n  public 'siteId' =\u003e string '1129402680464567580' (length=19)\n  public 'score' =\u003e float 0.40566906\n  public 'fields' =\u003e\n    array (size=9)\n      0 =\u003e\n        object(stdClass)[715]\n          public 'field' =\u003e string 'author' (length=6)\n          public 'value' =\u003e string 'i form' (length=6)\n      1 =\u003e\n        object(stdClass)[718]\n          public 'field' =\u003e string 'bod-cat' (length=7)\n          public 'value' =\u003e string 'Sund graviditet' (length=15)\n      2 =\u003e\n        object(stdClass)[719]\n          public 'field' =\u003e string 'bod-cat-top' (length=11)\n          public 'value' =\u003e string 'Sundhed' (length=7)\n      3 =\u003e\n        object(stdClass)[720]\n          public 'field' =\u003e string 'bod-cat-url' (length=11)\n          public 'value' =\u003e string 'http://iform.dk/sundhed/sund-graviditet' (length=39)\n      4 =\u003e\n        object(stdClass)[721]\n          public 'field' =\u003e string 'bod-pagetype' (length=12)\n          public 'value' =\u003e string 'article' (length=7)\n      5 =\u003e\n        object(stdClass)[722]\n          public 'field' =\u003e string 'description' (length=11)\n          public 'value' =\u003e string 'Går du med babytanker, har du en fordel, hvis du bor tæt på din mor.' (length=71)\n      6 =\u003e\n        object(stdClass)[723]\n          public 'field' =\u003e string 'recs-publishtime' (length=16)\n          public 'value' =\u003e string '2015-04-19T22:00:00.000Z' (length=24)\n      7 =\u003e\n        object(stdClass)[724]\n          public 'field' =\u003e string 'title' (length=5)\n          public 'value' =\u003e string 'Din mor øger dine baby-chancer' (length=31)\n      8 =\u003e\n        object(stdClass)[725]\n          public 'field' =\u003e string 'url' (length=3)\n          public 'value' =\u003e string 'http://iform.dk/sundhed/sund-graviditet/din-mor-kan-hjaelpe-til-familieforoegelsen' (length=82)\n```\n\n#### Widget documents\n\nIf the key 'widget_id' is missing from the input array then a [WidgetMissingId](https://github.com/BenjaminMedia/wp-cxense/blob/search_documents/src/Bonnier/WP/Cxense/Exceptions/WidgetMissingId.php) exception is thrown.\n\nExample how to fetch cxense data\n``` php\nWidgetDocumentQuery::make()\n                    -\u003eaddContext('url', get_permalink())\n                    -\u003esetMatchingMode($this-\u003egetCxenseTaxonomy())\n                    -\u003eaddParameter('pageType', 'article gallery story')\n                    -\u003esetCategories(array($this-\u003egetCategory()))\n                    -\u003esetTags(array($this-\u003egetTag()))\n                    -\u003eget();\n```\n\n#### Recently viewed by user 'TAX_RECENT'\nThis type of taxonomy requires user browser cookie. In order to fetch it from the browser console you can use\n```\ncX.getUserId()\n```\n\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenjaminmedia%2Fwp-cxense","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fbenjaminmedia%2Fwp-cxense","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fbenjaminmedia%2Fwp-cxense/lists"}