{"id":456,"date":"2019-02-21T15:42:47","date_gmt":"2019-02-21T14:42:47","guid":{"rendered":"https:\/\/numa-bord.com\/miniblog\/?p=456"},"modified":"2019-02-21T15:46:08","modified_gmt":"2019-02-21T14:46:08","slug":"wordpress-remplacer-la-fonction-dun-plugin-utilisant-iffunction_exist","status":"publish","type":"post","link":"https:\/\/numa-bord.com\/miniblog\/wordpress-remplacer-la-fonction-dun-plugin-utilisant-iffunction_exist\/","title":{"rendered":"WordPress : Remplacer la fonction d&rsquo;un plugin utilisant if(!function_exist())"},"content":{"rendered":"<p>Souvent les plugins wordpress d\u00e9clarent leurs fonctions dans une condition <strong>\u00ab\u00a0if(!function_exist())\u00a0\u00bb<\/strong> de ce type : <\/p>\n<div class=\"codecolorer-container php default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"php codecolorer\"><span class=\"kw1\">if<\/span> <span class=\"br0\">&#40;<\/span><span class=\"sy0\">!<\/span><a href=\"http:\/\/www.php.net\/function_exists\"><span class=\"kw3\">function_exists<\/span><\/a><span class=\"br0\">&#40;<\/span><span class=\"st_h\">'la_fonction_du_plugin'<\/span><span class=\"br0\">&#41;<\/span><span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw2\">function<\/span> la_fonction_du_plugin<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\">\/\/code de la fonction<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\">\/\/...<\/span><br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><\/div><\/div>\n<p>Si le plugin ne propose pas de m\u00e9thode permettant d&rsquo;overrider le fichier contenant cette fonction ni de hook pour la modifier on se retrouve bloqu\u00e9. Mais on peux tirer avantage que la fonction soit englober dans un \u00ab\u00a0if(!function_exist())\u00a0\u00bb pour ne pas modifier le coeur du plugin est ainsi continuer \u00e0 pouvoir profiter des mises \u00e0 jour.<\/p>\n<p>La solution consiste \u00e0 d\u00e9clarer la m\u00eame fonction mais avant que le fichier du plugin qui la contient soit charg\u00e9. C&rsquo;est ici que se situe l&rsquo;astuce, rien de plus simple quand on sait que wordpress propose un syst\u00e8me de <strong>\u00ab\u00a0must use plugins\u00a0\u00bb<\/strong>. Il suffit de placer un fichier php dans le dossier <strong>\u00ab\u00a0\/wp-content\/mu-plugins\u00a0\u00bb<\/strong> (on cr\u00e9e le dossier si il n&rsquo;existe pas). Ce fichier sera automatiquement charg\u00e9 avant tous les autres plugins. On peux placer plusieurs fichiers, peu importe leur noms qui seront alors charg\u00e9 dans l&rsquo;ordre alphab\u00e9tique. Appelons par exemple notre fichier <strong>\u00ab\u00a0load.php\u00a0\u00bb<\/strong> et rempla\u00e7ons notre fonction :<\/p>\n<div class=\"codecolorer-container php default\" style=\"overflow:auto;white-space:nowrap;\"><div class=\"php codecolorer\"><span class=\"kw1\">if<\/span> <span class=\"br0\">&#40;<\/span><span class=\"sy0\">!<\/span><a href=\"http:\/\/www.php.net\/function_exists\"><span class=\"kw3\">function_exists<\/span><\/a><span class=\"br0\">&#40;<\/span><span class=\"st_h\">'la_fonction_du_plugin'<\/span><span class=\"br0\">&#41;<\/span><span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; <span class=\"kw2\">function<\/span> la_fonction_du_plugin<span class=\"br0\">&#40;<\/span><span class=\"br0\">&#41;<\/span> <span class=\"br0\">&#123;<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\">\/\/code modifi\u00e9 de la fonction<\/span><br \/>\n&nbsp; &nbsp; &nbsp; &nbsp; <span class=\"co1\">\/\/...<\/span><br \/>\n&nbsp; &nbsp; <span class=\"br0\">&#125;<\/span><br \/>\n<span class=\"br0\">&#125;<\/span><\/div><\/div>\n<p>C&rsquo;est tout simple, encore faut il connaitre cette possibilit\u00e9 et l&rsquo;existence des \u00ab\u00a0must use plugins\u00a0\u00bb. Bien sur on peux se servir de ce fichier pour excuter n&rsquo;importe quel code avant que le reste ne soit charg\u00e9 (plugins, th\u00e8me)<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Souvent les plugins wordpress d\u00e9clarent leurs fonctions dans une condition \u00ab\u00a0if(!function_exist())\u00a0\u00bb de ce type : if &#40;!function_exists&#40;&rsquo;la_fonction_du_plugin&rsquo;&#41;&#41; &#123; &nbsp; &nbsp; function la_fonction_du_plugin&#40;&#41; &#123; &nbsp; &nbsp; &nbsp; &nbsp; \/\/code de la fonction &nbsp; &nbsp; &nbsp; &nbsp; \/\/&#8230; &nbsp; &nbsp; &#125; &#125; Si le plugin ne propose pas de m\u00e9thode permettant d&rsquo;overrider le fichier contenant cette fonction [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[2,6],"tags":[],"class_list":["post-456","post","type-post","status-publish","format-standard","hentry","category-developpement","category-wordpress"],"acf":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.2 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Wordpress : Remplacer la fonction d&#039;un plugin utilisant if(!function_exist()) - Pense b\u00eate d&#039;un d\u00e9veloppeur web<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/numa-bord.com\/miniblog\/wordpress-remplacer-la-fonction-dun-plugin-utilisant-iffunction_exist\/\" \/>\n<meta property=\"og:locale\" content=\"fr_FR\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Wordpress : Remplacer la fonction d&#039;un plugin utilisant if(!function_exist()) - Pense b\u00eate d&#039;un d\u00e9veloppeur web\" \/>\n<meta property=\"og:description\" content=\"Souvent les plugins wordpress d\u00e9clarent leurs fonctions dans une condition \u00ab\u00a0if(!function_exist())\u00a0\u00bb de ce type : if &#040;!function_exists&#040;&#039;la_fonction_du_plugin&#039;&#041;&#041; &#123; &nbsp; &nbsp; function la_fonction_du_plugin&#040;&#041; &#123; &nbsp; &nbsp; &nbsp; &nbsp; \/\/code de la fonction &nbsp; &nbsp; &nbsp; &nbsp; \/\/... &nbsp; &nbsp; &#125; &#125; Si le plugin ne propose pas de m\u00e9thode permettant d&rsquo;overrider le fichier contenant cette fonction [&hellip;]\" \/>\n<meta property=\"og:url\" content=\"https:\/\/numa-bord.com\/miniblog\/wordpress-remplacer-la-fonction-dun-plugin-utilisant-iffunction_exist\/\" \/>\n<meta property=\"og:site_name\" content=\"Pense b\u00eate d&#039;un d\u00e9veloppeur web\" \/>\n<meta property=\"article:published_time\" content=\"2019-02-21T14:42:47+00:00\" \/>\n<meta property=\"article:modified_time\" content=\"2019-02-21T14:46:08+00:00\" \/>\n<meta name=\"author\" content=\"Numa\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"\u00c9crit par\" \/>\n\t<meta name=\"twitter:data1\" content=\"Numa\" \/>\n\t<meta name=\"twitter:label2\" content=\"Dur\u00e9e de lecture estim\u00e9e\" \/>\n\t<meta name=\"twitter:data2\" content=\"1 minute\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/numa-bord.com\/miniblog\/wordpress-remplacer-la-fonction-dun-plugin-utilisant-iffunction_exist\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/numa-bord.com\/miniblog\/wordpress-remplacer-la-fonction-dun-plugin-utilisant-iffunction_exist\/\"},\"author\":{\"name\":\"Numa\",\"@id\":\"https:\/\/numa-bord.com\/miniblog\/#\/schema\/person\/f9d00acd1703f17e5a6895283eb46a7e\"},\"headline\":\"WordPress : Remplacer la fonction d&rsquo;un plugin utilisant if(!function_exist())\",\"datePublished\":\"2019-02-21T14:42:47+00:00\",\"dateModified\":\"2019-02-21T14:46:08+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/numa-bord.com\/miniblog\/wordpress-remplacer-la-fonction-dun-plugin-utilisant-iffunction_exist\/\"},\"wordCount\":277,\"commentCount\":0,\"articleSection\":[\"D\u00e9veloppement\",\"Wordpress\"],\"inLanguage\":\"fr-FR\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/numa-bord.com\/miniblog\/wordpress-remplacer-la-fonction-dun-plugin-utilisant-iffunction_exist\/#respond\"]}]},{\"@type\":\"WebPage\",\"@id\":\"https:\/\/numa-bord.com\/miniblog\/wordpress-remplacer-la-fonction-dun-plugin-utilisant-iffunction_exist\/\",\"url\":\"https:\/\/numa-bord.com\/miniblog\/wordpress-remplacer-la-fonction-dun-plugin-utilisant-iffunction_exist\/\",\"name\":\"Wordpress : Remplacer la fonction d'un plugin utilisant if(!function_exist()) - Pense b\u00eate d&#039;un d\u00e9veloppeur web\",\"isPartOf\":{\"@id\":\"https:\/\/numa-bord.com\/miniblog\/#website\"},\"datePublished\":\"2019-02-21T14:42:47+00:00\",\"dateModified\":\"2019-02-21T14:46:08+00:00\",\"author\":{\"@id\":\"https:\/\/numa-bord.com\/miniblog\/#\/schema\/person\/f9d00acd1703f17e5a6895283eb46a7e\"},\"breadcrumb\":{\"@id\":\"https:\/\/numa-bord.com\/miniblog\/wordpress-remplacer-la-fonction-dun-plugin-utilisant-iffunction_exist\/#breadcrumb\"},\"inLanguage\":\"fr-FR\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/numa-bord.com\/miniblog\/wordpress-remplacer-la-fonction-dun-plugin-utilisant-iffunction_exist\/\"]}]},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/numa-bord.com\/miniblog\/wordpress-remplacer-la-fonction-dun-plugin-utilisant-iffunction_exist\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Accueil\",\"item\":\"https:\/\/numa-bord.com\/miniblog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"WordPress : Remplacer la fonction d&rsquo;un plugin utilisant if(!function_exist())\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/numa-bord.com\/miniblog\/#website\",\"url\":\"https:\/\/numa-bord.com\/miniblog\/\",\"name\":\"Pense b\u00eate d&#039;un d\u00e9veloppeur web\",\"description\":\"(php, javascript, Symfony, Wordpress....)\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/numa-bord.com\/miniblog\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"fr-FR\"},{\"@type\":\"Person\",\"@id\":\"https:\/\/numa-bord.com\/miniblog\/#\/schema\/person\/f9d00acd1703f17e5a6895283eb46a7e\",\"name\":\"Numa\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"fr-FR\",\"@id\":\"https:\/\/secure.gravatar.com\/avatar\/f21d1af4658a7106211915940584534c1e0b3eef3f12eb67a697686cad70b64a?s=96&d=mm&r=g\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/f21d1af4658a7106211915940584534c1e0b3eef3f12eb67a697686cad70b64a?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/f21d1af4658a7106211915940584534c1e0b3eef3f12eb67a697686cad70b64a?s=96&d=mm&r=g\",\"caption\":\"Numa\"},\"url\":\"https:\/\/numa-bord.com\/miniblog\/author\/negonner\/\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Wordpress : Remplacer la fonction d'un plugin utilisant if(!function_exist()) - Pense b\u00eate d&#039;un d\u00e9veloppeur web","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/numa-bord.com\/miniblog\/wordpress-remplacer-la-fonction-dun-plugin-utilisant-iffunction_exist\/","og_locale":"fr_FR","og_type":"article","og_title":"Wordpress : Remplacer la fonction d'un plugin utilisant if(!function_exist()) - Pense b\u00eate d&#039;un d\u00e9veloppeur web","og_description":"Souvent les plugins wordpress d\u00e9clarent leurs fonctions dans une condition \u00ab\u00a0if(!function_exist())\u00a0\u00bb de ce type : if &#40;!function_exists&#40;'la_fonction_du_plugin'&#41;&#41; &#123; &nbsp; &nbsp; function la_fonction_du_plugin&#40;&#41; &#123; &nbsp; &nbsp; &nbsp; &nbsp; \/\/code de la fonction &nbsp; &nbsp; &nbsp; &nbsp; \/\/... &nbsp; &nbsp; &#125; &#125; Si le plugin ne propose pas de m\u00e9thode permettant d&rsquo;overrider le fichier contenant cette fonction [&hellip;]","og_url":"https:\/\/numa-bord.com\/miniblog\/wordpress-remplacer-la-fonction-dun-plugin-utilisant-iffunction_exist\/","og_site_name":"Pense b\u00eate d&#039;un d\u00e9veloppeur web","article_published_time":"2019-02-21T14:42:47+00:00","article_modified_time":"2019-02-21T14:46:08+00:00","author":"Numa","twitter_card":"summary_large_image","twitter_misc":{"\u00c9crit par":"Numa","Dur\u00e9e de lecture estim\u00e9e":"1 minute"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/numa-bord.com\/miniblog\/wordpress-remplacer-la-fonction-dun-plugin-utilisant-iffunction_exist\/#article","isPartOf":{"@id":"https:\/\/numa-bord.com\/miniblog\/wordpress-remplacer-la-fonction-dun-plugin-utilisant-iffunction_exist\/"},"author":{"name":"Numa","@id":"https:\/\/numa-bord.com\/miniblog\/#\/schema\/person\/f9d00acd1703f17e5a6895283eb46a7e"},"headline":"WordPress : Remplacer la fonction d&rsquo;un plugin utilisant if(!function_exist())","datePublished":"2019-02-21T14:42:47+00:00","dateModified":"2019-02-21T14:46:08+00:00","mainEntityOfPage":{"@id":"https:\/\/numa-bord.com\/miniblog\/wordpress-remplacer-la-fonction-dun-plugin-utilisant-iffunction_exist\/"},"wordCount":277,"commentCount":0,"articleSection":["D\u00e9veloppement","Wordpress"],"inLanguage":"fr-FR","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/numa-bord.com\/miniblog\/wordpress-remplacer-la-fonction-dun-plugin-utilisant-iffunction_exist\/#respond"]}]},{"@type":"WebPage","@id":"https:\/\/numa-bord.com\/miniblog\/wordpress-remplacer-la-fonction-dun-plugin-utilisant-iffunction_exist\/","url":"https:\/\/numa-bord.com\/miniblog\/wordpress-remplacer-la-fonction-dun-plugin-utilisant-iffunction_exist\/","name":"Wordpress : Remplacer la fonction d'un plugin utilisant if(!function_exist()) - Pense b\u00eate d&#039;un d\u00e9veloppeur web","isPartOf":{"@id":"https:\/\/numa-bord.com\/miniblog\/#website"},"datePublished":"2019-02-21T14:42:47+00:00","dateModified":"2019-02-21T14:46:08+00:00","author":{"@id":"https:\/\/numa-bord.com\/miniblog\/#\/schema\/person\/f9d00acd1703f17e5a6895283eb46a7e"},"breadcrumb":{"@id":"https:\/\/numa-bord.com\/miniblog\/wordpress-remplacer-la-fonction-dun-plugin-utilisant-iffunction_exist\/#breadcrumb"},"inLanguage":"fr-FR","potentialAction":[{"@type":"ReadAction","target":["https:\/\/numa-bord.com\/miniblog\/wordpress-remplacer-la-fonction-dun-plugin-utilisant-iffunction_exist\/"]}]},{"@type":"BreadcrumbList","@id":"https:\/\/numa-bord.com\/miniblog\/wordpress-remplacer-la-fonction-dun-plugin-utilisant-iffunction_exist\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Accueil","item":"https:\/\/numa-bord.com\/miniblog\/"},{"@type":"ListItem","position":2,"name":"WordPress : Remplacer la fonction d&rsquo;un plugin utilisant if(!function_exist())"}]},{"@type":"WebSite","@id":"https:\/\/numa-bord.com\/miniblog\/#website","url":"https:\/\/numa-bord.com\/miniblog\/","name":"Pense b\u00eate d&#039;un d\u00e9veloppeur web","description":"(php, javascript, Symfony, Wordpress....)","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/numa-bord.com\/miniblog\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"fr-FR"},{"@type":"Person","@id":"https:\/\/numa-bord.com\/miniblog\/#\/schema\/person\/f9d00acd1703f17e5a6895283eb46a7e","name":"Numa","image":{"@type":"ImageObject","inLanguage":"fr-FR","@id":"https:\/\/secure.gravatar.com\/avatar\/f21d1af4658a7106211915940584534c1e0b3eef3f12eb67a697686cad70b64a?s=96&d=mm&r=g","url":"https:\/\/secure.gravatar.com\/avatar\/f21d1af4658a7106211915940584534c1e0b3eef3f12eb67a697686cad70b64a?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/f21d1af4658a7106211915940584534c1e0b3eef3f12eb67a697686cad70b64a?s=96&d=mm&r=g","caption":"Numa"},"url":"https:\/\/numa-bord.com\/miniblog\/author\/negonner\/"}]}},"_links":{"self":[{"href":"https:\/\/numa-bord.com\/miniblog\/wp-json\/wp\/v2\/posts\/456","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/numa-bord.com\/miniblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/numa-bord.com\/miniblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/numa-bord.com\/miniblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/numa-bord.com\/miniblog\/wp-json\/wp\/v2\/comments?post=456"}],"version-history":[{"count":5,"href":"https:\/\/numa-bord.com\/miniblog\/wp-json\/wp\/v2\/posts\/456\/revisions"}],"predecessor-version":[{"id":461,"href":"https:\/\/numa-bord.com\/miniblog\/wp-json\/wp\/v2\/posts\/456\/revisions\/461"}],"wp:attachment":[{"href":"https:\/\/numa-bord.com\/miniblog\/wp-json\/wp\/v2\/media?parent=456"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/numa-bord.com\/miniblog\/wp-json\/wp\/v2\/categories?post=456"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/numa-bord.com\/miniblog\/wp-json\/wp\/v2\/tags?post=456"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}