{"id":1205,"date":"2019-05-15T02:06:35","date_gmt":"2019-05-15T02:06:35","guid":{"rendered":"https:\/\/docs.control-webpanel.com\/docs\/developer-tools\/custom-modules\/user"},"modified":"2020-02-27T14:08:15","modified_gmt":"2020-02-27T14:08:15","slug":"user","status":"publish","type":"docs","link":"https:\/\/docs.control-webpanel.com\/docs\/developer-tools\/custom-modules\/user","title":{"rendered":"User"},"content":{"rendered":"<p><strong>To start we must create the following files:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>1. <code>\/usr\/local\/cwpsrv\/var\/services\/user_files\/modules\/MY_MODULE.php<\/code><\/p>\n<p>2. <code>\/usr\/local\/cwpsrv\/var\/services\/users\/cwp_lang\/en\/MY_MODULE.ini<\/code><\/p>\n<p>3. <code>\/usr\/local\/cwpsrv\/var\/services\/users\/cwp_theme\/original\/mod_MY_MODULE.html<\/code><\/p>\n<p>&nbsp;<\/p>\n<p><strong>Where:<\/strong><\/p>\n<p>&nbsp;<\/p>\n<p>1. <strong>MY_MODULE.php<\/strong>: It is the file that will contain your new module, take into account that here you could be using the following variables:<\/p>\n<ul>\n<li style=\"list-style-type: none;\">\n<ul>\n<li>$ _SESSION [&#8216;username&#8217;]: User name of the account.<\/li>\n<li>$ _SESSION [&#8216;tokenuser&#8217;]: User session token.<\/li>\n<li>$ mod []: Fix with module information.<\/li>\n<\/ul>\n<\/li>\n<\/ul>\n<p><em>Example:<\/em><\/p>\n<pre><code>&lt;?php\r\nif(isset($_GET['acc'])){\r\n    if($_GET['acc']=='regards'){\r\n        echo 'Hello, This is a greeting from ajax to mymodule';\r\n        die;\r\n    }\r\n}\r\n\r\n$mod['dateday']=date('Y-m-d H:i:s');\r\n$mod['msj']='Hi ';\r\n\r\n?&gt;<\/code><\/pre>\n<p>2. <strong>MY_MODULE.ini<\/strong>: It is the language file, it is mandatory for the English language.<\/p>\n<p>&nbsp;<\/p>\n<p><em>Example:<\/em><\/p>\n<pre><code>LABEL1=\"Today's date is:\"\r\nLABEL2=\"Click here\"\r\n<\/code><\/pre>\n<p>&nbsp;<\/p>\n<p>3. <strong>mod_MY_MODULE.html<\/strong>: It is the template of the theme, this file is required can receive parameters from the file MY_MODULE.php through the $ mod array using <a href=\"https:\/\/twig.symfony.com\/\">the template engine in Twig<\/a> integrated to cwp.<\/p>\n<p>&nbsp;<\/p>\n<p>Example:<\/p>\n<p>&nbsp;<\/p>\n<pre><code>&lt;div class=\"row\"&gt;\r\n    &lt;div class=\"col-lg-12\"&gt;\r\n        &lt;strong&gt;{{mod.msj}} &lt;\/strong&gt;{{langmod.LABEL1}} : {{mod.dateday}}\r\n    &lt;\/div&gt;\r\n    &lt;div&gt;\r\n        &lt;button id=\"btn_hi\" class=\"btn btn-xs btn-success\"&gt;{{langmod.LABEL2}}&lt;\/button&gt;\r\n    &lt;\/div&gt;\r\n&lt;\/div&gt;<\/code><\/pre>\n<p>In html templates you can make calls to the following variables of type array:<br \/>\n<strong>$mod<\/strong> = All the data that you send for it from the php<br \/>\n<strong>$langmod<\/strong> = All language tags<\/p>\n<p>&nbsp;<\/p>\n<p>It is recommended to place all the javascript code in a library with extension .twig.<\/p>\n<p>Example = \/usr\/local\/cwpsrv\/var\/services\/users\/cwp_theme\/MY_THEME\/js\/MY_JS.js.twig<\/p>\n<p>Where the calls to ajax can be in this way:<\/p>\n<pre><code>\r\n$(\"#<code>btn_hi<\/code>\").click(function (){ $.ajax({ type: \"POST\", url: \".\/{{users}}\/index.php?module=MY_MODULE&amp;acc=regards\", complete: function(datos){ alert(datos.responseText); return false; } }); return false; }); <\/code><\/pre>\n<p>&nbsp;<\/p>\n<p><strong>Note<\/strong>: It is recommended to clone the original theme and work on the copy since cwp updates always overwrite the original theme.<\/p>\n<p>&nbsp;<\/p>\n<p style=\"text-align: center;\"><a href=\"https:\/\/docs.control-webpanel.com\/wp-content\/uploads\/2019\/05\/testmodule.tar.gz\">Download the demo module here<\/a><\/p>\n<div id=\"gtx-trans\" style=\"position: absolute; left: 625px; top: 1446px;\">\n<div class=\"gtx-trans-icon\"><\/div>\n<\/div>\n","protected":false},"author":4,"featured_media":0,"parent":574,"menu_order":1,"comment_status":"closed","ping_status":"closed","template":"","meta":[],"doc_tag":[],"_links":{"self":[{"href":"https:\/\/docs.control-webpanel.com\/wp-json\/wp\/v2\/docs\/1205"}],"collection":[{"href":"https:\/\/docs.control-webpanel.com\/wp-json\/wp\/v2\/docs"}],"about":[{"href":"https:\/\/docs.control-webpanel.com\/wp-json\/wp\/v2\/types\/docs"}],"author":[{"embeddable":true,"href":"https:\/\/docs.control-webpanel.com\/wp-json\/wp\/v2\/users\/4"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.control-webpanel.com\/wp-json\/wp\/v2\/comments?post=1205"}],"version-history":[{"count":34,"href":"https:\/\/docs.control-webpanel.com\/wp-json\/wp\/v2\/docs\/1205\/revisions"}],"predecessor-version":[{"id":1834,"href":"https:\/\/docs.control-webpanel.com\/wp-json\/wp\/v2\/docs\/1205\/revisions\/1834"}],"up":[{"embeddable":true,"href":"https:\/\/docs.control-webpanel.com\/wp-json\/wp\/v2\/docs\/574"}],"prev":[{"title":"Admin","link":"https:\/\/docs.control-webpanel.com\/docs\/developer-tools\/custom-modules\/admin","href":"https:\/\/docs.control-webpanel.com\/wp-json\/wp\/v2\/docs\/1204"}],"wp:attachment":[{"href":"https:\/\/docs.control-webpanel.com\/wp-json\/wp\/v2\/media?parent=1205"}],"wp:term":[{"taxonomy":"doc_tag","embeddable":true,"href":"https:\/\/docs.control-webpanel.com\/wp-json\/wp\/v2\/doc_tag?post=1205"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}