메소드를 액션에 연결하려면 (예 : 테마의 에서) 클래스의 인스턴스가 필요합니다.
네임 스페이스 내에서 AdManager
클래스를 고려하십시오
<code class="language-php">class AdManager { public function adsense() { ?> <ins data-ad-client="ca-pub-xxxxxxxxxxxxxxxx" data-ad-slot="6762452247" style="display:inline-block;width:336px;height:280px"></ins> (adsbygoogle = window.adsbygoogle || []).push({}); <?php } public function buysellads() { // ... } public static function get_instance() { static $instance = null; if ( $instance == null ) { $instance = new self(); } return $instance; } }</code>
adsense
호출과 클래스가 동일한 네임 스펙이있는 파일에 있으면 선불이 엄격하게 필요하지 않습니다. 동일하게 네임 스펙트 드 함수에도 적용됩니다
before_post_content
add_action( 'before_post_content', array( AdManager::get_instance(), 'adsense' ) );
위 내용은 WordPress 후크 시스템의 네임 스페이스 이해의 상세 내용입니다. 자세한 내용은 PHP 중국어 웹사이트의 기타 관련 기사를 참조하세요!